So I just learned about the .dockerignore
file after realising how uploading my context
to the docker deamon got 1.5 GB big and took forever.
Look at the ref docs here: https://docs.docker.com/engine/reference/builder/#dockerignore-file
But the kicker was to find out how to use it as a whitelist and ignore everything but the stuff u need docker to put in your container:
# Ignore everything
*
# only add prebuild binary
!bin/linux/*
This turns out to be a lifesaver bin node/rust projects where the working directory contains a giant pile of generated/compiled junk!
Top comments (1)
Yeah that is very crutial. There is yet another trick when building rust docker images, to keep the build time low, and take full advantage of the docker build cache. That is build a project from scratch, copy only over you Cargo.{lock,toml}, run a build.
That trick will cause a pull and build of all dependencies, so that docker can cache that, and next time when you have changes only on your code, it will skip those steps because at this time you've only copied over the Cargo files and no code at all. See a rough draft below: