Docker Certification Training Course : Lecture 3

What is Docker Image ? Usually launching an application requires an OS, environment, app artifact, web server, etc. Docker Image consists of different packages, called layers, each layer representing what was listed before (OS, web server etc). Actually, pulling an image from Docker Hub is a sequential pulling a number of packages, layers. An output of docker inspect command applied to Docker Image contains Layers section containing layers’ hash codes :

Layers of inspected image

In /var/lib/docker there is a directory overlay2, which is the default storage driver (there are multiple storage drivers in Docker, like AUFS, overlay2, devicemapper, brtfs, ext4, xfs, each one is based on a Linux file system ; for windows machine storage driver is called windowsfilter, it implements a layering on top of NTFS file system). overlay2 directory stores layers (file named after layers sha256 hashcodes). When creating a Docker Container from a Docker Image, Docker goes to overlay2 directory, looking for layers containing in this directory. There is also a folder named image in /var/lib/docker directory. Inside image folder there are imagedb and layerdb folders. /var/lib/docker/image/overlay2/imagedb/content/sha256 folder contains localhost images’ layers. /var/lib/docker/image/overlay2/imagedb/content/sha256 folder contains layers used when creating containers from localhost images (see Layers of inspected image picture above). Same layer can be used by multiple images.

pvs – Unix command displaying an information about the physical volumes in OS

lvs – Unix command displaying an information about the logical volumes in OS

Unlike Docker Containers, Docker Images are unable to be changed. This is because of Docker Containers are supplied with so called thin writable on top of them, Run C component of Docker is providing thin writable layer on top of Docker Container. Thin writable layer itself is not a layer, it is a tool providing a functionality to make changes on top of Docker Container. Docker Images are not supplied with thin writable layer.

Any additional change inside the container causes new layer creation.

There are different ways to create an own image :

  • Manual
  • Automatic via Dockerfile

Example of manual way is creating a container using nginx, but under Ubuntu OS (by default nginx is using Debian OS). Command docker run -it ubuntu, followed by entering the container in interactive mode and installing nginx does the work. Note that in this case port won’t be assigned to nginx by default. Base ubuntu layer does not use any port.

docker commit <container_id> <image name> – command for converting Docker Container into a Docker Image

docker search <word> – command displaying all image names from Docker Hub containing given word

docker commit command is useful because it lets creating customized images

Using Dockerfile (automatic way of creating image), though, is considered to be a better approach.

DockerFile should never be created in a root directory structure. Separate folder must be used.


Leave a Reply

Your email address will not be published. Required fields are marked *