Docker build cache doesn't work with cargo build.
Why? Because Docker cache is handled by checksuming all added resources using COPY ( see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache ) and then if anything si changed in added resources in future build run all cached instructions after this COPY are invalidated and executed again.
Example of current build:
FROM: rust COPY . /build/ RUN cargo build
This will download all dependencies on every docker build commend when any file in project is changed. There are several ways how to solve this e.g. use experimental build feature to mount dependencies from developer host machine into docker build, but this is still considered experimental and filesystem mounting is not simple between host machine and docker vm on platforms other than Linux.
Example in case of --dependencies-only support:
FROM: rust COPY Cargo.* /build/ RUN cargo build --dependencies-only COPY src /build/ RUN cargo build
This would allow to leverage Docker cache which will get invalidated after Cargo.* files are changes which is expected behaviour. As workaround one could create fake source file and build fake hello word project and then build with proper src files but this is really ugly workaround.
Let's add support to install only dependencies to simplify ergonomics of building rust projects not just in docker.