Optimize the Docker Image Size

Cleaning up in the same layer

1
FROM ubuntu:14.04
2
RUN apt-get update && \
3
apt-get install -y curl python-pip && \
4
pip install requests && \
5
apt-get remove -y python-pip curl && \
6
rm -rf /var/lib/apt/lists/*
7
ADD ./my_service.py /my_service.py
8
ENTRYPOINT ["python", "/my_service.py"]
Copied!

Apt install with `--no-install-recommends`

1
...
2
RUN apt-get install -y --no-install-recommends curl python-pip
3
...
Copied!

Multi-Stage Builds

1
FROM golang:1.8-alpine as builder
2
RUN go get github.com/kardianos/govendor
3
RUN go get github.com/nicksnyder/go-i18n/goi18n
4
RUN go get github.com/jteeuwen/go-bindata/go-bindata
5
RUN make build # Exports binaries to to ./bin/$BINARY
6
7
FROM alpine
8
COPY --from=builder ./bin/replicated /bin/replicated
9
ENTRYPOINT ["/bin/replicated"]
Copied!

Using distroless base images

Dive - A tool for exploring a docker image

GitHub - wagoodman/dive: A tool for exploring each layer in a docker image
GitHub