---
# System prepended metadata

title: Layer Experiment

---

# Layer Experiment

Start Image:

```sh
debian:stable-slim
```

Dockerfile-a-b:

```docker
FROM debian:stable-slim

WORKDIR /home

RUN touch a.txt
RUN touch b.txt
```

Dockerfile-a-b-rmb:

```docker
FROM debian:stable-slim

WORKDIR /home

RUN touch a.txt
RUN touch b.txt
RUN rm b.txt
```

Dockerfile-b-a:

```docker
FROM debian:stable-slim

WORKDIR /home

RUN touch b.txt
RUN touch a.txt
```

```sh
[Sebi:~]$ docker inspect debian:stable-slim | jq -r ".[].RootFS.Layers|.[]"

sha256:3b06942f43725fc346c3963044896aa6da6293de8946bd24da10a1825dad7759

[Sebi:~]$ docker inspect debian-a-b | jq -r ".[].RootFS.Layers|.[]"

sha256:3b06942f43725fc346c3963044896aa6da6293de8946bd24da10a1825dad7759
sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
sha256:8cc910e06f0ce0eabb4a7b66c65b58a9c24d7fd1a6fc5fad6c43c696695f6d28
sha256:0fbcccb48ff4caa9a29f77c17cacd6b441c25fa311707423496086f60bb1012d

[Sebi:~]$ docker inspect debian-a-b-rmb | jq -r ".[].RootFS.Layers|.[]"

sha256:3b06942f43725fc346c3963044896aa6da6293de8946bd24da10a1825dad7759
sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
sha256:8cc910e06f0ce0eabb4a7b66c65b58a9c24d7fd1a6fc5fad6c43c696695f6d28
sha256:0fbcccb48ff4caa9a29f77c17cacd6b441c25fa311707423496086f60bb1012d
sha256:5b3c573ec2e7d37b32fa4150a8ea3a6d542e2362feb1c8b1080bc11bc830257c

[Sebi:~]$ docker inspect debian-b-a | jq -r ".[].RootFS.Layers|.[]"

sha256:3b06942f43725fc346c3963044896aa6da6293de8946bd24da10a1825dad7759
sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
sha256:cf0e7d263a9082bf356ebdf6c097d300d5e43abd41d303af8eda61c8b3dd38c4
sha256:4adb0dccf27f9b55c5447761bbf4a9e999f442deea43eecc7d0b6c61d907192c
```

```sh
$ docker history debian-a-b

IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
29fbc06d569f   3 days ago    RUN /bin/sh -c touch b.txt # buildkit           0B        buildkit.dockerfile.v0
<missing>      3 days ago    RUN /bin/sh -c touch a.txt # buildkit           0B        buildkit.dockerfile.v0
<missing>      3 days ago    WORKDIR /home                                   0B        buildkit.dockerfile.v0
<missing>      12 days ago   /bin/sh -c #(nop)  CMD ["bash"]                 0B
<missing>      12 days ago   /bin/sh -c #(nop) ADD file:6c109a1e0daaf36f7…   80.4MB
```

```sh
docker tag debian-a-b:latest s1e2b3i4/debian-a-b:latest

$ docker push s1e2b3i4/debian-a-b:latest

The push refers to repository [docker.io/s1e2b3i4/debian-a-b]
0fbcccb48ff4: Pushed
8cc910e06f0c: Pushed
5f70bf18a086: Mounted from dockerbase/openssh-server
3b06942f4372: Pushed
latest: digest: sha256:7abb745463d174d475addf3dee8bf197eb5ade049a36f80c29d96bddffecce9c size: 1149

$ docker pull s1e2b3i4/debian-a-b:latest
latest: Pulling from s1e2b3i4/debian-a-b
Digest: sha256:7abb745463d174d475addf3dee8bf197eb5ade049a36f80c29d96bddffecce9c
Status: Downloaded newer image for s1e2b3i4/debian-a-b:latest
docker.io/s1e2b3i4/debian-a-b:latest

$ docker manifest inspect s1e2b3i4/debian-a-b | jq -r ".layers|.[].digest"

sha256:c059e9850ae5d07e4b7328348ae3f34c06d2df64250cc4bd417f83ee57fd4c1b
sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
sha256:dfb204dc0fda7dd132e211474cd7de5e5ee52d79bd7f9656b06501ab6959c4e3
sha256:f56285b65df0bf0dab3be26977aae02aee36658a8d199d1acde47d2f367107d2

$ curl -H "Authorization: Bearer $(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:s1e2b3i4/debian-a-b:pull" 2>/dev/null| jq -r .token)" https://registry-1.docker.io/v2/s1e2b3i4/debian-a-b/manifests/latest 2>/dev/null| jq -r ".fsLayers|.[].blobSum"

sha256:f56285b65df0bf0dab3be26977aae02aee36658a8d199d1acde47d2f367107d2
sha256:dfb204dc0fda7dd132e211474cd7de5e5ee52d79bd7f9656b06501ab6959c4e3
sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
sha256:c059e9850ae5d07e4b7328348ae3f34c06d2df64250cc4bd417f83ee57fd4c1b
```

- The layer ID is a digest of its content
- An image contians contains an ordered list of layer digests
- The image ID is a digest of its configuration object
- The Manifest File contains the digest of the *compressed* layer contents

--> https://windsock.io/explaining-docker-image-ids/
