Docker Containers~!

Docker Containers~!

I never knew anything about dockers till about 7–8 weeks ago (as of writing this). I had come into contact with dockers only because of a school project. So why not document it……amiright? hehe lesgo~!


What is a Docker Container?

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it: code, runtime, system tools, system libraries, settings. Containers are an abstraction at the app layer that packages code and dependencies together. You can think of it as a virtual machine but way lighter! You can run multiple containers on the same machine whilst sharing the OS kernel with the containers! Containers also consume lesser storage space than VMs.

Docker ebook can be found here


Virtual Machines vs Container

Containers and virtual machines have similar resource isolation and allocation benefits but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.


Installing Docker [Linux]

Step 1 — Prepping our machine

We gotta make sure the system up to date!

[email protected]:~# apt-get update

You should have the following packages in your Kali install. If not run the following command to install them:

[email protected]:~# apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
Step 2— Adding the Docker Repository

Configure Docker apt repository:

[email protected]:~# echo ‘deb https://download.docker.com/linux/debian stretch stable’ > /etc/apt/sources.list(.d/docker.list)->optional
Step 3— Installing Docker onto the machine

Command to perform the installation:

[email protected]:~# apt-get install docker-ce docker-compose

Now that we have it installed Docker successfully, Lets verify the installation!

[email protected]:~# docker --versionDocker 
version 19.03.8, build afacb8b7f0

[email protected]:~#

Docker Search

We have a bunch of images that are provided by docker! Let's search for an image that we can create a container with. For this demo, I’m gonna look for a raspberry image that I can use.

[email protected]:~# docker search {image_name}
Docker Pull

Now that we have identified and verified that the image we want is available, let's pull it down to our machine.

[email protected]:~# docker pull {image_name}
Docker Images

Now that we have installed the image, let's verify that.

[email protected]:~# docker images

As seen above, the ubuntu image we downloaded shows up.

Docker Run

Now let's create a container with the base image that we just downloaded.

[email protected]:~# docker run -it --rm --name {containername} {image} 
{application to launch on start}


-it = Interactive mode (This allows u to interact with the shell as soon as it has launched)

--rm = remove the container totally on exit (wont be able to re enter the container)

--name = Gives the container a name

Now that we have launched a container successfully, let’s verify it with the following command!

[email protected]:/# uname -a

^disclaimer:the container launches with a random name everytime its relaunched

Now we are free to do whatever we please on the container :)

Docker Commit

A container starts up fresh unless we commit the contents of a particular container into an image. The first thing we need to do is run the container without the --rm . This will make sure that we are able to commit the container into an image on exit.

Now, make your necessary changes to the container and exit it gracefully.

On exit, enter the following command to commit this container into another image.

[email protected]:~# docker commit {container_name} {custom_image_name}

^disclaimer: the custom image name cant have any caps

If you receive the hash as seen above, we have committed the docker container successfully. The next time we launch the container we have to replace the {ubuntu} with {commitedcontainer}

[email protected]:~# docker run -it --rm --name {containername} {image}
Docker Remove

Now let’s say we have a container running and we are not inside of it to exit it because we launched it without the — -rm tag to commit it. This is how we shut down a container gracefully.

First, we need to find out what we would like to close. For that, we need to check the docker process list with this command.

[email protected]:~# docker ps -a

In the screenshot above, I have 2 containers running. Let's close those 2 containers. Command:

[email protected]:/# docker rm {container NAME} --force

That's about it! That's all you need to know to get started with docker! However, you will learn more along the way. Allthebest!

~Nee