Rust: How to build a Docker image with private Cargo dependencies

Example Application: Rocket-Add

I’ve developed an example API called Rocket-Add which is built on top of a very cool web framework in Rust called Rocket

$ curl localhost:8000/add/5/10
The sum of 5 and 10 is 15

Fetching crates in private repositories

Before we go any further, we’re going to take a page from Ruby Bundler’s book and create a local .cargo folder in the project root. This will provide a project-independent place to store our crates and Cargo config

git clone
cd rocket-add
mkdir -p $(git rev-parse --show-toplevel)/.cargo
export CARGO_HOME=$(git rev-parse --show-toplevel)/.cargo
$ cat .cargo/config
git-fetch-with-cli = true
math_utils = { version = "0.1.0", git = "ssh://"}

Building a Rust Docker image with private dependencies

A frequently encountered problem when building a Docker image is downloading private dependencies without mounting an SSH key




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store