4 ms·
Docker recently has support for multi stage builds. So you can use one Dockerfile to define how to build your image (produce your jar and necessary other resour
by bzajax 8y ago
Docker recently has support for multi stage builds. So you can use one Dockerfile to define how to build your image (produce your jar and necessary other resources) and then copy them into a fresh container running off a more lightweight image that might not contain all the intermediates and your build tools.
https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds https://docs.docker.com/develop/develop-images/multistage-bu...
- zokier 8y agoMulti-stage builds is definitely my preferred method of building stuff, but the problem I've found is that caching dependencies is bit of a pain, either you need to do some tricks with volumes or your builds will be very slow.
- kinghajj 8y agoAt work, I setup the build system to use Apache Archiva to cache Java dependencies, along with other services like apt-cacher, devpi, and squid, for Debian, Python, and general HTTP caching, respectively. We build all of our images atop the "bitnami/minideb" base, and split the Dockerfiles into "partials" that source a dynamic parent image via a build argument. For example, the partial that sets up Debian package and HTTP caching: ARG base FROM ${base} ARG apt_cacher_host ARG http_proxy ARG https_proxy ARG no_proxy ENV HTTP_PROXY="${http_proxy}" ENV HTTPS_PROXY="${https_proxy}" ENV NO_PROXY="${no_proxy}" ENV http_proxy="${http_proxy}" ENV https_proxy="${https_proxy}" ENV no_proxy="${no_proxy}" RUN set -ex; \ if [ ! -z "${apt_cacher_host}" ]; then \ echo "Acquire::http::Proxy \"${apt_cacher_host}\";Acquire::https::Proxy \"false\";" >/etc/apt/apt.conf.d/01proxy; \ fi; \ For Java, another partial creates a Maven settings file with the Apache Archiva URL: ARG base FROM ${base} ARG maven_mirror COPY devops/image-partials/java-artifacts/settings.xml /tmp/settings.xml RUN set -ex; \ env; \ if [ ! -z "${maven_mirror}" ]; then \ sed -r "s!%%MAVEN_MIRROR%%!${maven_mirror}!g;" /tmp/settings.xml >/usr/share/maven/conf/settings.xml; \ fi; The important part of settings.xml is this section: <mirrors> <mirror> <id>archiva.default</id> <url>%%MAVEN_MIRROR%%</url> <mirrorOf>external:*</mirrorOf> </mirror> </mirrors> And voila, Maven will go through Archiva for all its dependencies, which are transparently cached so that subsequent builds don't need to re-download everything again.
- jacques_chester 8y ago> Docker recently has support for multi stage builds. I view these as a future antipattern. They bring what is properly CI's work inside the Docker daemon, which makes it a larger attack surface (many folks run PRs sight-unseen) and obscures it from outside tooling. They only exist because of the limits of the Dockerfile format. With something like Jib, that disappears.