Difficulty: beginner
Estimated Time: 45-60 minutes

BoxBoat Logo

Docker Engine Lab

Now that we've got some experience working with Docker, let's take a deep dive into some of the technical underpinnings of the Docker Engine.

Please email feedback to: [email protected]

Now that we've gone over a few advanced Docker topics, we'll cover how to build Docker images.

Docker Engine

Step 1 of 5

Docker Images

Docker Images are where you store your application code, dependencies, and configuration for your applications.

Docker Images are made up of many different layers. These layers are immutable.

docker image inspect alpine

[[email protected] ~]# docker image inspect alpine
[
    {
        "Id": "sha256:3fd9065eaf02feaf94d68376da52541925650b81698c53c6824d92ff63f98353",
        "RepoTags": [
            "alpine:latest"
        ],
        "RepoDigests": [
            "[email protected]:7b848083f93822dd21b0a2f14a110bd99f6efb4b838d499df6d04a49d0debf8b"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2018-01-09T21:10:58.579708634Z",
        "Container": "30e1a2427aa2325727a092488d304505780501585a6ccf5a6a53c4d83a826101",
        "ContainerConfig": {
            "Hostname": "30e1a2427aa2",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/bin/sh\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:fbef17698ac8605733924d5662f0cbfc0b27a51e83ab7d7a4b8d8a9a9fe0d1c2",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "17.06.2-ce",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:fbef17698ac8605733924d5662f0cbfc0b27a51e83ab7d7a4b8d8a9a9fe0d1c2",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 4143449,
        "VirtualSize": 4143449,
        "GraphDriver": {
            "Data": {
                "RootDir": "/var/lib/docker/overlay/709d704b273230997f7df2f0257070877e56f2096358be1ab1d46c85b24c50cd/root"
            },
            "Name": "overlay"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:cd7100a72410606589a54b932cabd804a17f9ae5b42a1882bd56d263e02b6215"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

If we look at the data, we can see that these layers are stored: /var/lib/docker/overlay. We can go to the subdirectories under /var/lib/docker/overlay to view the individual layers:

[[email protected] root]# pwd
/var/lib/docker/overlay/709d704b273230997f7df2f0257070877e56f2096358be1ab1d46c85b24c50cd/root
[[email protected] root]# ls
bin  etc   lib    mnt   root  sbin  sys  usr
dev  home  media  proc  run   srv   tmp  var

Some of these will be links to the host filesystem, while others will be binaries or simple bash scripts.

These individual layers are combined using the graph driver. There are different storage technologies that Docker can use, but in general it is recommended to use the overlay2 driver, which will be used by default in most cases.

There are also open-source tools you can use to view the layers of a Docker container. One such tool is called dive. Tools like this are great if you are trying to find ways to reduce the overall size of a Docker image you are building, or to interactively inspect what is in each layer.