There are many ready-to-use images on Docker Hub. You can also find an official image here: https://hub.docker.com/_/rust/. But we will create our own image since official images contain a stable compiler version only. If it's enough for you, it's better to use official images, but if you use crates such as diesel, which need the nightly version of the Rust compiler, you will have to build your own image to build microservices.
Create a new Dockerfile and add the following content to it:
FROM buildpack-deps:stretch
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH
RUN set -eux; \
url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
wget "$url"; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path -...