`COPY –chmod` reduced the size of my container image by 35%
In my experience docker-slim[0] is the way to go for creating minimal and secure Docker images.<p>I wasted a lot of time in the past trying to ship with Alpine base images and statically compiling complicated software. All the performance, compatibility, package availability headaches this brings is not worth it when docker-slim does a better job of removing OS from your images while letting you use any base image you want.<p>Tradeoff is that you give up image layering to some extent and it might take a while to get dead-file-elimination exactly right if your software loads a lot of files dynamically (you can instruct docker-slim to include certain paths and probe your executable during build).<p>If docker-slim is not your thing, “distroless” base images [1] are also pretty good. You can do your build with the same distro and then in a multi stage docker image copy the artifacts into distroless base images.<p>[0] <a href="https://github.com/docker-slim/docker-slim" rel="nofollow">https://github.com/docker-slim/docker-slim</a><p>[1] <a href="https://github.com/GoogleContainerTools/distroless" rel="nofollow">https://github.com/GoogleContainerTools/distroless</a>