Created
October 5, 2019 16:10
-
-
Save pkhuong/8eb9340137bfca7ce45c92b50cc6b0fa to your computer and use it in GitHub Desktop.
Single layer docker image with build artifacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM alpine:latest AS builder | |
| RUN echo "foo" > /foo.txt | |
| FROM scratch | |
| COPY --from=builder /*.txt . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pkhuong@penguin:/tmp/docker-hack$ docker -v | |
| Docker version 19.03.3-beta2, build dede96ff4c | |
| pkhuong@penguin:/tmp/docker-hack$ docker build . | |
| Sending build context to Docker daemon 2.048kB | |
| Step 1/4 : FROM alpine:latest AS builder | |
| latest: Pulling from library/alpine | |
| 9d48c3bd43c5: Pull complete | |
| Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb | |
| Status: Downloaded newer image for alpine:latest | |
| ---> 961769676411 | |
| Step 2/4 : RUN echo "foo" > /foo.txt | |
| ---> Running in ae75064a947b | |
| Removing intermediate container ae75064a947b | |
| ---> ef6c6067c3e2 | |
| Step 3/4 : FROM scratch | |
| ---> | |
| Step 4/4 : COPY --from=builder /*.txt . | |
| ---> e61754c79a6b | |
| Successfully built e61754c79a6b | |
| pkhuong@penguin:/tmp/docker-hack$ docker save e61754c79a6b > test.tar | |
| pkhuong@penguin:/tmp/docker-hack$ mkdir test | |
| pkhuong@penguin:/tmp/docker-hack$ cd test | |
| pkhuong@penguin:/tmp/docker-hack/test$ tar -xf ../test.tar | |
| pkhuong@penguin:/tmp/docker-hack/test$ ls | |
| 07901039823771394504e93342ba3fce4d42bf59ebbed88091fda9175fba4af7 e61754c79a6bd2012097a7663013b7f0b7dff75afc7bac5bd4120a09657996f1.json manifest.json | |
| pkhuong@penguin:/tmp/docker-hack/test$ mkdir -p /tmp/docker-hack/layer; cd /tmp/docker-hack/layer | |
| pkhuong@penguin:/tmp/docker-hack/layer$ tar -xf ../test/07901039823771394504e93342ba3fce4d42bf59ebbed88091fda9175fba4af7/layer.tar | |
| pkhuong@penguin:/tmp/docker-hack/layer$ ls | |
| foo.txt | |
| pkhuong@penguin:/tmp/docker-hack/layer$ cat foo.txt | |
| foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment