-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Being a fan of both Rust and Docker, I tried to run Cargo inside a Docker container. Unfortunately this doesn't currently work so well. Here's an example repo: https://github.com/jnicklas/rust_docker_test
Running this like this:
docker build -t test . && docker run -it testResults in output like this:
An unknown error occurred
couldn't prepare build directories for `rust_docker_test`
Caused by:
couldn't rename path (Invalid cross-device link; from=/var/app/target/release/.fingerprint; to=/var/app/target/release/old-fingerprint)
It seems that cargo hardlinks files in the process of calling run. Unfortunately because of the way that docker build up the file system out of separate layers, these files are on separate devices.
It is of course possible to remove the docker build --release line from the Dockerfile, but then the entire compilation needs to be redone every time the container is run, which is unacceptably slow.
It seems that Cargo isn't really at fault here. It's after all doing something which under normal circumstances should work, it's just that it interacts in an unfortunate way with the way that Docker works, which makes it tricky to get performant build via Docker.
I have no idea on what an appropriate solution to this problem would be, but I thought that I'd document it here in any case.