Understanding Dockers — part 1

Puneet Khanna
4 min readDec 9, 2021

--

Dockers were designed to pack and ship applications in an independent / isolated objects with life — containers . The user who uses these containers sees that a container is an isolated machine[We will talk about process ,resource isolation later ] and can run the code /app inside that. The process that helps run these containers is Docker runtime.To re-iterate -Docker is a container technology that helps provision these containers. Also,containers run on/with the env provided by docker runtime.Think of this as a VMware Kernel on your ESX box

As you create VMs from ovfs/templates, you create containers from docker images , these images are stored at a common repository called hub(it can be local or external hub)

How to install docker on ubuntu:- https://docs.docker.com/engine/install/ubuntu/

Command to know the docker version and list containers

How to create a container from image ubuntu?

If you do not have an image on local , the docker tries to download that from the hub. So when you issue the following command , it checks the local images first and then decides if it should be downloaded if absent

user@nest:~/Desktop$ sudo docker run ubuntu
Unable to find image ‘ubuntu:latest’ locally
latest: Pulling from library/ubuntu
7b1a6ab2e44d: Pull complete
Digest: sha256:626ffe58f6e7566e00254b638eb7e0f3b11d4da9675088f4781a50ae288f3322
Status: Downloaded newer image for ubuntu:lates
t

But wait , when you say docker ps to list running containers , it doesn't list it ?

user@nest:~/Desktop$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
user@nest:~/Desktop$

because the container exited , just issue docker ps -a to find that out, this lists the already exited / dead containers

But why the container exited ? due to an error? No, it has exit code as 0 .

The dockers are not designed to run OS , they are designed to run processes but incase the docker has nothing to run and it has finished its job it will exit

To make the ubuntu image last longer we will pass a command line option as in the below command, -d in the below command is to run the container in the detached mode i.e in the background ,if you see the docker ps after issuing the below command, you will see the container running in the background

docker run -d ubuntu sleep 60

Did you notice anything so far? That the ubuntu image is no longer downloaded from the internet , it is because it is cached on the local disk, to view downloaded images , issue docker images and it will list them. More about images in the below -section

Docker Images

The command to list the images is docker images . You can see in the session below that i removed image ubuntu after removing all containers . The command i used to delete images is docker rmi <imageName> and to remove containers it is , docker rm <cotainerId>. Please note that i created an alias of the command sudo docker as sd so that i dont have to type that over and over ( please read it as sudo docker ) .if you see below when i deleted the ubuntu image ,i tried to create a container with image ubuntu and it downloaded it again. From now onwards if i wanted to create a new container of ubuntu , the local copy will be used

How to know the properties of a container or in short what makes a container as a running entity , it is docker inspect <containerIdentity> .Please see the below session for a glimpse and try on your box .

--

--