Closed luser closed 6 years ago
Hmm. Couldn't you do (2) manually when you invoke the container? I'm reluctant to hard-code a VOLUME
into the container, because that can have some surprising consequences for people who don't know about it, or who want clean production builds.
I can, yeah. It would be nice to at least provide this as an alternative in the documentation for people who want it. I understand wanting to have defaults that work well for most people, but this is pretty painful and it breaks a built-in cargo feature (caching) that people expect to have.
For anyone else wondering how to do this correctly, here's an example:
mkdir -p "${project_root}/target/musl-builder/cargo-cache"
docker run --rm -it \
-v "${project_root}":/home/rust/src \
-v "${project_root}/target/musl-builder/cargo-cache":/home/rust/.cargo/registry \
ekidd/rust-musl-builder cargo build --release
The registry cache will not lie in the made-up target/musl-builder
directory, while the image will still use the same cargo
version that is installed in the image.
I hope this helps someone.
Thank you, that's a nice solution! I would be happy to include a version of these instructions in the README.md
file if anybody wants to submit a PR.
I'm going to close this issue for now, but please feel free to submit a PR with instructions.
It would be nice if the cargo cache for this image wasn't ephemeral so that every rebuild didn't wind up re-downloading all the crates it needs. I can think of two ways do to this: 1) Use
VOLUME ~rust/.cargo
to make the .cargo directory a persistent data volume: https://docs.docker.com/engine/reference/builder/#/volume (This must be done after all the steps in the Dockerfile that will write data to that directory.) 2) Change the alias to mount the host ~/.cargo as ~rust/.cargo, to share the cargo cache from the host system.