Instantly share code, notes, and snippets.

View docker_squas_output.txt
$ docker build --squash -t app-squashed .
$ docker history app-squashed
IMAGE CREATED CREATED BY SIZE COMMENT
c3f98f9241fc 2 hours ago 0B merge sha256:7ee5b606949f15cdfc790a44b49ea83b2ae7c8be808eedfb74234b47a50e66f1 to sha256:b9e15a5d1e1a11a69061b1dc2e3641805a2dc54e1338faf7f87f4c2c21ed3e6a
<missing> 2 hours ago /bin/sh -c rm -rf app.zip 0B
<missing> 2 hours ago /bin/sh -c chmod 777 app.zip 0B
<missing> 2 hours ago /bin/sh -c #(nop) ADD file:b12845ba907bbbc42… 0B
<missing> 8 days ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 8 days ago /bin/sh -c mkdir -p /run/systemd && echo 'do… 7B
<missing> 8 days ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$… 2.76kB
View unsquashed_image_sizes
$ docker build -t app-unsquashed .
$ docker history app-unsquashed
IMAGE CREATED CREATED BY SIZE COMMENT
7ee5b606949f 1 hour ago /bin/sh -c rm -rf app.zip 0B
7df1dc446bd0 2 hour ago /bin/sh -c chmod 777 app.zip 210MB
71530d33b38b 2 huor ago /bin/sh -c #(nop) ADD file:b12845ba907bbbc42… 210MB
b9e15a5d1e1a 8 days ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B
<missing> 8 days ago /bin/sh -c mkdir -p /run/systemd && echo 'do… 7B
<missing> 8 days ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$… 2.76kB
<missing> 8 days ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0B
View illustrate_squash.Dockerfile
## Dockerfile, with RUN uncombined
FROM ubuntu:16.04
ADD app.zip . # App of 200 MB
RUN chmod 777 app.zip
RUN rm -rf app.zip
## Dockerfile, with RUN combined
FROM ubuntu:16.04
ADD app.zip . # App of 200 MB
RUN chmod 777 app.zip && rm -rf app.zip
View c-multi-stage.Dockerfile
### Below is used for representation purpose and is not in any way a working Dockerfile.
FROM alpine:latest
RUN apk update && apk add --no-cache gcc musl-dev
COPY <prg>.c .
RUN gcc -static -o <prg> <prg>.c
FROM alpine:latest
COPY --from=0 <prg> /usr/bin/<prg>
ENTRYPOINT ["/usr/bin/<prg>"]
View builder_pattern.Dockerfile
### Below is used for representation purpose and is not in any way a working Dockerfile.
### Build the artifact using Dockerfile.build
docker build -t artifact-build -f Dockerfile.build
### Create the container using the image to obtain artifact
docker create --name artifact-container artifact-build
### Copy the artifact from container to host machine
docker cp artifact-conatiner:<src_path_of_artifact> <host_machine_path>
View leaner_images_1.Dockerfile
### Below is used for representation purpose and is not in any way a working Dockerfile.
### Dockerfile - I
FROM ubuntu:18.04
ENV APP_USER=TEST
ENV APP_PORT=8080
RUN apt-get update
RUN apt-get install -y pkg1 pkg2 pkg3
RUN mkdir -p /usr/src/test-dir