- Create a simple Dockerfile to build an apline image.
- Use
build
and buildx build
to build the same Dockerfile.
- Examine the image layer.
FROM alpine
RUN apk add --no-cache bash
COPY . /app
RUN chmod +x /app/hello.sh
CMD /app/hello.sh
$ docker build -t img0 .
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM alpine
latest: Pulling from library/alpine
2408cc74d12b: Pull complete
Digest: sha256:686d8c9dfa6f3ccfc8230bc3178d23f84eeaf7e457f36f271ab1acc53015037c
Status: Downloaded newer image for alpine:latest
---> e66264b98777
Step 2/5 : RUN apk add --no-cache bash
---> Running in 8d4bb9012c59
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ncurses-terminfo-base (6.3_p20220521-r0)
(2/4) Installing ncurses-libs (6.3_p20220521-r0)
(3/4) Installing readline (8.1.2-r0)
(4/4) Installing bash (5.1.16-r2)
Executing bash-5.1.16-r2.post-install
Executing busybox-1.35.0-r13.trigger
OK: 8 MiB in 18 packages
Removing intermediate container 8d4bb9012c59
---> c30c4ade8d67
Step 3/5 : COPY . /app
---> 14ab7c71e803
Step 4/5 : RUN chmod +x /app/hello.sh
---> Running in 8fc8c2d9a28e
Removing intermediate container 8fc8c2d9a28e
---> f11502e3c083
Step 5/5 : CMD /app/hello.sh
---> Running in 3f00d75f1bd4
Removing intermediate container 3f00d75f1bd4
---> a7323ea78a43
Successfully built a7323ea78a43
Successfully tagged img0:latest
$ docker buildx build -t img1 .
[+] Building 4.6s (9/9) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 137B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 0.0s
=> [1/4] FROM docker.io/library/alpine 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 212B 0.0s
=> [2/4] RUN apk add --no-cache bash 3.9s
=> [3/4] COPY . /app 0.0s
=> [4/4] RUN chmod +x /app/hello.sh 0.4s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:c6cfc6f9688fb5aca23bfc128cb326c90d07ae420456f3c3a0b558ec7f0bfc6c 0.0s
=> => naming to docker.io/library/img1
$ docker image history img0
IMAGE CREATED CREATED BY SIZE COMMENT
a7323ea78a43 2 minutes ago /bin/sh -c #(nop) CMD ["/bin/sh" "-c" "/app… 0B
f11502e3c083 2 minutes ago /bin/sh -c chmod +x /app/hello.sh 38B
14ab7c71e803 2 minutes ago /bin/sh -c #(nop) COPY dir:d7e62b3bbd2c3347c… 138B
c30c4ade8d67 2 minutes ago /bin/sh -c apk add --no-cache bash 2.15MB
e66264b98777 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 6 weeks ago /bin/sh -c #(nop) ADD file:8e81116368669ed3d… 5.53MB
$ docker image history img1
IMAGE CREATED CREATED BY SIZE COMMENT
c6cfc6f9688f 38 seconds ago CMD ["/bin/sh" "-c" "/app/hello.sh"] 0B buildkit.dockerfile.v0
<missing> 38 seconds ago RUN /bin/sh -c chmod +x /app/hello.sh # buil… 38B buildkit.dockerfile.v0
<missing> 39 seconds ago COPY . /app # buildkit 138B buildkit.dockerfile.v0
<missing> 39 seconds ago RUN /bin/sh -c apk add --no-cache bash # bui… 2.15MB buildkit.dockerfile.v0
<missing> 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/sh"] 0B
<missing> 6 weeks ago /bin/sh -c #(nop) ADD file:8e81116368669ed3d… 5.53MB
$ docker image inspect a7323ea78a43
[
{
"Id": "sha256:a7323ea78a43a11df6abe8eccd920621e8b595cf23875cb246f0538aaf75c6ff",
"RepoTags": [
"img0:latest"
],
"RepoDigests": [],
"Parent": "sha256:f11502e3c08353b0504528c22cb09b677d8afbfc4956a95870925e5968363543",
"Comment": "",
"Created": "2022-07-06T12:40:27.051022433Z",
"Container": "3f00d75f1bd4383bfc75e7aae5024e22e0f2099451ab84223dfe565d96e8624a",
"ContainerConfig": {
"Hostname": "3f00d75f1bd4",
"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\" \"-c\" \"/app/hello.sh\"]"
],
"Image": "sha256:f11502e3c08353b0504528c22cb09b677d8afbfc4956a95870925e5968363543",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"DockerVersion": "20.10.17",
"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",
"-c",
"/app/hello.sh"
],
"Image": "sha256:f11502e3c08353b0504528c22cb09b677d8afbfc4956a95870925e5968363543",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 7677757,
"VirtualSize": 7677757,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/13307c9f5368dc3ffe7f835b64d6dd8f843c604f2679fa5ee08f241db98bf5ce/diff:/var/lib/docker/overlay2/1e3797cb8f3c5c499f1bd5a9b9fd76b0452350b15724c42340330d8c12b6249a/diff:/var/lib/docker/overlay2/9f7f7dbdc8dd5732b0da5aec52cd16f9a144181533bb02134ef990d3fd313624/diff",
"MergedDir": "/var/lib/docker/overlay2/11d90a52784c4bfe1405fa6d3fd5bcaacf47365354dd56e887d3b16413144b86/merged",
"UpperDir": "/var/lib/docker/overlay2/11d90a52784c4bfe1405fa6d3fd5bcaacf47365354dd56e887d3b16413144b86/diff",
"WorkDir": "/var/lib/docker/overlay2/11d90a52784c4bfe1405fa6d3fd5bcaacf47365354dd56e887d3b16413144b86/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:24302eb7d9085da80f016e7e4ae55417e412fb7e0a8021e95e3b60c67cde557d",
"sha256:25ece83ddc8aa2e3aed147f65c223cfe6eede2e99852af949144e0bc92fe720c",
"sha256:d520722da3f37c656c0d1730ecbb2c935be859a26f1d5725cb9bed839fa58804",
"sha256:9045588752f71bdd537f2d634818739acf9d275e86ea2479a2139a19a1847079"
]
},
"Metadata": {
"LastTagTime": "2022-07-06T20:43:02.062852034+08:00"
}
}
]
$ docker image inspect c6cfc6f9688f
[
{
"Id": "sha256:c6cfc6f9688fb5aca23bfc128cb326c90d07ae420456f3c3a0b558ec7f0bfc6c",
"RepoTags": [
"img1:latest"
],
"RepoDigests": [],
"Parent": "",
"Comment": "buildkit.dockerfile.v0",
"Created": "2022-07-06T20:42:49.076111009+08:00",
"Container": "",
"ContainerConfig": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": null,
"Cmd": null,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"DockerVersion": "",
"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",
"-c",
"/app/hello.sh"
],
"ArgsEscaped": true,
"Image": "",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"Architecture": "amd64",
"Os": "linux",
"Size": 7677675,
"VirtualSize": 7677675,
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/c8k5fvkar7hk9tu8tj6jaeox1/diff:/var/lib/docker/overlay2/46yyctaxts7ssul5ie8rd450s/diff:/var/lib/docker/overlay2/9f7f7dbdc8dd5732b0da5aec52cd16f9a144181533bb02134ef990d3fd313624/diff",
"MergedDir": "/var/lib/docker/overlay2/o8uhrtev6jlr4z8pxvuz2rl3c/merged",
"UpperDir": "/var/lib/docker/overlay2/o8uhrtev6jlr4z8pxvuz2rl3c/diff",
"WorkDir": "/var/lib/docker/overlay2/o8uhrtev6jlr4z8pxvuz2rl3c/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:24302eb7d9085da80f016e7e4ae55417e412fb7e0a8021e95e3b60c67cde557d",
"sha256:30b9f345d55995a166db38ec93a7b59efb84b14d886dbebe80c3328e9d3f08a1",
"sha256:822031192040976c804ae851b7c2792f98790e3e370a837de09d2050b1d07e0c",
"sha256:0383043465c7d472e68115983939bc58e374e9a8283dd8b0538a1be7fe3d6807"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]