apt remove in Docker layers will no twork
Closed this issue · 2 comments
Hi Sören
Line 39 in 7fe0dae
this will not work, if you want to save image sizes
because Docker images are composed in layers
every RUN command is one layer and will be safed (like in git)
you need to COPY first and merge the RUN commands in to one big command
then you can apt remove
the packages as last (all in the same Docker layer)
SECOND OPTION (better)
install and compile all in an build layer
https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
notice COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
you will copy the compiled files to a clean new image
and the build layer will be erased
CLI TOOLS TO RESCUE
- https://github.com/wagoodman/dive - to inspect docker layer to shrink image size
- https://github.com/hadolint/hadolint - Dockerfile linter
ah
and try to take debian:stretch-slim this will safe also some MB
and http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz
should not be hard coded
move the url in a variable
ARG BERKLY_PKG_URL=http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz
# Install Berkeley DB 4.8
RUN curl -L $BERKLY_PKG_URL | tar -xz -C /tmp && \
you can pass parameters to the docker build
command via --build-arg
docker build -t xsn-test-build --build-arg BERKLY_PKG_URL=http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz .