Latest Rust compiler and cargo in a linux container (using docker).
The images are available in my Docker Hub repository:
$ docker pull tomastomecek/rust
— this is the most recent stable release$ docker pull tomastomecek/rust:nightly
— this is the most recent, functional nightly release$ docker pull tomastomecek/rust:clippy
— latest nightly image with clippy
Every stable image is also tagged with version of Rust compiler, so for example:
$ docker pull tomastomecek/rust:1.17.0
For more info what versions are available, see the section Tags.
You should mount your project inside directory /src
within the container. cargo
and rustc
commands are then available in the container.
Here is a guide how to perform some common actions:
- Compile a file:
$ ls -lha .
total 4.0K
-rw-rw-r-- 1 me me 37 May 23 13:10 main.rs
$ docker run -ti -v $PWD:/src/ tomastomecek/rust rustc ./main.rs
$ ./main
It works!
$ ls -lha .
total 3.5M
-rwxr-xr-x 1 me me 3.5M May 26 18:11 main
-rw-rw-r-- 1 me me 37 May 23 13:10 main.rs
- Create a new project using cargo:
$ mkdir the-best-project
$ cd the-best-project
$ docker run -ti -v $PWD:/src/ tomastomecek/rust cargo init --bin
Created binary (application) project
$ ls -lha .
total 8.0K
drwxrwxr-x 4 me me 61 May 26 18:35 .
drwxrwxr-x 7 me me 143 May 26 18:29 ..
-rw-r--r-- 1 me me 76 May 26 18:35 Cargo.toml
drwxr-xr-x 6 me me 96 May 26 18:17 .git
-rw-r--r-- 1 me me 120 May 26 18:35 .gitignore
drwxr-xr-x 2 me me 19 May 26 18:35 src
- Compile a cargo project:
$ ls -lh .
total 8.0K
-rw-r--r-- 1 me me 76 May 26 18:35 Cargo.toml
drwxr-xr-x 2 me me 19 May 26 18:35 src
$ docker run -ti -v $PWD:/src/ tomastomecek/rust cargo build
Compiling src v0.1.0 (file:///src)
Finished dev [unoptimized + debuginfo] target(s) in 0.34 secs
$ ./target/debug/src
Hello, world!
These images are being created using a very simple CI/CD pipeline. Here's how it works:
-
Travis CI initiates a build every day using its Cron Jobs feature.
-
This build script is executed.
-
Rust stable docker image is built.
-
Tests for Rust stable docker image are executed. These tests verify that
- Rust compiler is able to compile Rust code.
- Cargo is able to create a new project.
- This cargo project can be built.
-
If the tests passed, push the image to Docker Hub.
-
Do steps 3 and 4 for nightly image.
With this very simple pipeline you can be sure that
- you get functional images
- you get latest Rust compiler
- you can pick a version of Rust