0

Rust And Ubuntu 18.04 Docker Image

Last Updated on

This post shows how to build a Ubuntu 18.04 Docker image with installed Rust. We can use the image to build Rust applications, but the codes are in the host Windows system. When we compile the codes, we need to specify the local Windows directory as a volume in Docker.

Requirements For Docker Image

We used the following items.

  1. Ubuntu 18.04 Docker image as the base image
  2. Rust 1.42.0, which is the latest version as of this writing
  3. Windows 10, which is our host system
  4. Docker 2.2.0.4 Community for Windows
  5. Enable File Sharing and choose the local drives where the codes are
  6. Cargo project with Cargo.toml
  7. Windows 10

Build Docker Image With Dockerfile

Okay, we start with a Dockerfile.

Line 1 specifies that we use Ubuntu 18.04 as the base of our Docker image. Next, we update the operating system and install the curl with -y option. Then, we create and directory for our WORKDIR.

Finally, we install Rust. We also need to set the environment PATH to Cargo’s bin directory.

We need to build our Docker image. Go to the Windows Commandline, the run the following command.

We’ll get something like the following output.

Verify  Rust Installation in Docker

To verify the Rust installation in Ubuntu 18.04, we can check out Cargo’s version and make it compile code. Note – we don’t have any codes when we start up a Docker container.

All commands are on the Windows command line prompt.

First, we run Cargo with –version option.

The command produces the following output.

Next, we make Cargo build codes using the following command.

The command produces the following output.

The error indicates that the directory is empty. It is okay for now because we don’t have Rust codes yet to compile.

If we have the codes in a local directory, we use this command. It will compile the Rust codes in the Windows host.

Avatar

Karl San Gabriel

Professional Software Developer