skip to Main Content

I am trying to understand the docker images a bit better. Most of the instructions in a dockerfile creates a layer.
So when we have the command:

COPY hom* /mydir/

this creates a layer and according to the doc

The COPY instruction copies new files or directories from <src> and
adds them to the filesystem of the container at the path <dest>.

It says in the container and not the image though. Does that mean that the layer itself holds the files and the instruction and when the docker runs the container the layer is essentially an execution at runtime of the command?
I am a bit confused on what constitutes the layer at a lower level

2

Answers


  1. Does that mean that the layer itself holds the files

    Yes.

    and the instruction

    Yes, in the form of history. See docker history <image>.

    when the docker runs the container the layer is essentially an execution at runtime of the command?

    No, the command was executed in the past and resulted in a layer consisting of files. When the image is executed, the layers of files are laid on top of each other, resulting in a file system.

    what constitutes the layer at a lower level

    Files, files everywhere. This also depends on your used dockerd storage driver and file system. Typically, with OverlayFS, there are just directories in /var/lib/docker/overlay2 with files. When image is started, directories are "laid on top of each other" with OverlayFS resulting in a file system of all files from all folders.

    You might also be interested in https://docs.docker.com/storage/storagedriver/select-storage-driver/ in particular https://docs.docker.com/storage/storagedriver/overlayfs-driver/#how-the-overlay2-driver-works .

    Login or Signup to reply.
  2. I post this answer to give some more information about the storage drivers that in Docker handle the layers and image creation.

    From this link
    What is the difference between a Docker image and a container?
    you can understand better the difference between images and containers. Basically an image is a group of layers while a container is an instance of an image.

    Docker uses storage drivers to:

    • store image layers
    • store data, both in read-only or writable mode, in the layer of a container
    • control how images and containers are stored and managed on your host.

    Every line you write in the Dockerfile creates a layer that will store on the filesystem and will contribute to compose the overall Docker image.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search