cargo chef cook generates rust-toolchain.toml file, but it's not used in the subsequent build of dependencies.
rust-toolchain.toml takes effect when cargo is invoked next time. Therefore, executing cargo chef cook twice results in building with the wrong toolchain for the first time and the correct building for the second time.
The following Dockerfile reproduces the problem.
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
FROM chef AS planner
RUN echo '[workspace]\nresolver = "2"\nmembers = ["hello"]' > Cargo.toml
RUN cargo new hello
RUN echo '[toolchain]\nchannel = "1.75.0"' > rust-toolchain.toml
RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json # does not install 1.75.0
RUN cargo chef cook --release --recipe-path recipe.json # does install 1.75.0
cargo chef cook
generates rust-toolchain.toml file, but it's not used in the subsequent build of dependencies. rust-toolchain.toml takes effect whencargo
is invoked next time. Therefore, executingcargo chef cook
twice results in building with the wrong toolchain for the first time and the correct building for the second time.The following Dockerfile reproduces the problem.