$ cargo new hello_world Cargo defaults to --bin to make a binary program. To make a library, we would pass --lib, instead. Let’s check out what Cargo has generated for us: $ cd hello_world $ tree . . ├── Cargo.toml └── src └── main.rs 1 directory, 2 files This is all we need to get started. First, let’s check out Cargo.toml:
The --frozen flag also prevents Cargo from attempting to access the network to determine if it is out-of-date. These may be used in environments where you want to assert that the Cargo.lock file is up-to-date (such as a CI build) or want to avoid network access.--offline Prevents Cargo from accessing the network for any reason.
Whenever a dependency from a git repository is specified without any other specifiers (namely via the properties , rev, or tag), that means that it is specified to the latest revision of the main branch of that repository. But in any case, updating any dependency requires updating the project's Cargo.lock file. This generally means using the branch command.cargo update
cargo update
This will also detect any changes to the version or origin requirements and update the dependency lock accordingly.
I tried to use this command:
cargo install rust_wheel --force
That is the wrong Cargo command. is for installing binaries to the system, not to install dependencies. This is well documented too.cargo install
Also tried
.cargo update rust_wheel
Wrong syntax. To issue an update of a specific dependency, use the option.-p
cargo update -p rust_wheel
See also:
A volume inside the Dockerfile is counter-productive here. That would mount an anonymous volume at each build step, and again when you run the container. The volume during each build step is discarded after that step completes, which means you would need to download the entire contents again for any other step needing those dependencies.
The standard model for this is to copy your dependency specification, run the dependency download, copy your code, and then compile or run your code, in 4 separate steps. That lets docker cache the layers in an efficient manner. I'm not familiar with rust or cargo specifically, but I believe that would look like:
FROM rust:1.33.0
RUN rustup default nightly-2019-01-29
COPY Cargo.toml .
RUN cargo fetch # this should download dependencies
COPY src/ ./src/
RUN ["cargo", "build", "-Z", "unstable-options", "--out-dir", "/output"]
Another option is to turn on some experimental features with BuildKit (available in 18.09, released 2018-11-08) so that docker saves these dependencies in what is similar to a named volume for your build. The directory can be reused across builds, but never gets added to the image itself, making it useful for things like a download cache.
# syntax=docker/dockerfile:experimental
FROM rust:1.33.0
VOLUME ["/output", "/usr/local/cargo"]
RUN rustup default nightly-2019-01-29
COPY Cargo.toml .
COPY src/ ./src/
RUN --mount=type=cache,target=/root/.cargo \
["cargo", "build", "-Z", "unstable-options", "--out-dir", "/output"]
Note that the above assumes cargo is caching files in /root/.cargo. You'd need to verify this and adjust as appropriate. I also haven't mixed the mount syntax with a json exec syntax to know if that part works. You can read more about the BuildKit experimental features here: https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md
Turning on BuildKit from 18.09 and newer versions is as easy as and then running your build from that shell.export DOCKER_BUILDKIT=1