rmoh21
rmoh21

Reputation: 1525

Docker Image file details

Is a Docker Image file equivalent to a manifest file which contains pointers to what is present inside the Docker Image - aka the different layers - the amalgamation of which is the Docker Image

OR

Is a docker image file a monolithic image housing all the different layers within it and not necessarily pointing to different sub layers?

Upvotes: 2

Views: 584

Answers (1)

Matt
Matt

Reputation: 74680

A Docker image is essentially a JSON manifest that includes, among other things, references to file system layers by a SHA256 content checksum.

A layer is a read only set of filesystem changes, that when combined with the other layers produces the file system for your image.

Layers can be shared between images

Inspecting an Image

The RootFS property of docker inspect <image> lists the layers for an image

→ docker inspect openjdk:8-jre-alpine
[
    {
        "Id": "sha256:d85b17c6762eb3455c7b7ff1930bdde8c911137fe8c7f3c0b5988c66149dc27b",
        "RepoTags": [
            "openjdk:8-jre-alpine"
        ],
        "RepoDigests": [
            "openjdk@sha256:48ac96e309a748f5778db26be7e45ca0e35931ef58e9b271fe36767a55411728"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2016-12-27T18:38:49.797530681Z",
        "Container": "de5e277bf3e5ac747933bbb8e703382b240fdcdaef9d927faa4e02c1f0cbc35e",
        "ContainerConfig": {
            "Hostname": "26ba10d264c2",
            "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:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk/jre",
                "JAVA_VERSION=8u111",
                "JAVA_ALPINE_VERSION=8.111.14-r0"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "set -x \t&& apk add --no-cache \t\topenjdk8-jre=\"$JAVA_ALPINE_VERSION\" \t&& [ \"$JAVA_HOME\" = \"$(docker-java-home)\" ]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:7bf1d56e53b8a99662fc8314d3860b68f30798646ca0265aeeaa1275f679d314",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
        "DockerVersion": "1.12.3",
        "Author": "",
        "Config": {
            "Hostname": "26ba10d264c2",
            "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:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk/jre",
                "JAVA_VERSION=8u111",
                "JAVA_ALPINE_VERSION=8.111.14-r0"
            ],
            "Cmd": null,
            "ArgsEscaped": true,
            "Image": "sha256:7bf1d56e53b8a99662fc8314d3860b68f30798646ca0265aeeaa1275f679d314",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 107853459,
        "VirtualSize": 107853459,
        "GraphDriver": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/fccc5a703d4022f0fb561a3d0bc6c75da8a99aa1b3291f6be92bf8908e8d5add/diff:/var/lib/docker/overlay2/96ba8cd8b7b44ef284070bd4b98d912fd0bd2b9d6a0d906e661db901408ef38e/diff",
                "MergedDir": "/var/lib/docker/overlay2/890f1dbb6c802344c58a32e0ee6d2b49dea74418963ab10a0b649ddc50da6127/merged",
                "UpperDir": "/var/lib/docker/overlay2/890f1dbb6c802344c58a32e0ee6d2b49dea74418963ab10a0b649ddc50da6127/diff",
                "WorkDir": "/var/lib/docker/overlay2/890f1dbb6c802344c58a32e0ee6d2b49dea74418963ab10a0b649ddc50da6127/work"
            }
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:7cbcbac42c44c6c38559e5df3a494f44987333c8023a40fec48df2fce1fc146b",
                "sha256:da07d9b32b0090fa42690c204d7b49925b5e65ea770893d02c01ab00d61ff920",
                "sha256:6f7515f190962a84c9837ad7adb1e684d79fa0d798a57a99fbe090cc0f97f39c"
            ]
        }
    }
]

You can see from the docker history of the image, there were three commands in the Dockerfile that modified the file system. All other commands contribute to the metadata associated with the image (Use --no-trunc to get the full output)

→ docker history openjdk:8-jre-alpine
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
d85b17c6762e        2 months ago        /bin/sh -c set -x  && apk add --no-cache  ...   103 MB              
<missing>           2 months ago        /bin/sh -c #(nop)  ENV JAVA_ALPINE_VERSION...   0 B                 
<missing>           2 months ago        /bin/sh -c #(nop)  ENV JAVA_VERSION=8u111       0 B                 
<missing>           2 months ago        /bin/sh -c #(nop)  ENV PATH=/usr/local/sbi...   0 B                 
<missing>           2 months ago        /bin/sh -c #(nop)  ENV JAVA_HOME=/usr/lib/...   0 B                 
<missing>           2 months ago        /bin/sh -c {   echo '#!/bin/sh';   echo 's...   87 B                
<missing>           2 months ago        /bin/sh -c #(nop)  ENV LANG=C.UTF-8             0 B                 
<missing>           2 months ago        /bin/sh -c #(nop) ADD file:eeed5f514a35d18...   4.8 MB              

Upvotes: 3

Related Questions