Install Rust on Docker

The offical way of installing rust is to call a shell script from a remote host as follows:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

As documented here: https://www.rust-lang.org/tools/install, however, I'm not comfortable trusting that script, and when you are running a CI/CD setup, that would be calling their script a lot. I am not comfortable with this approach from a security and load perspective. In the long run, the rust developers should consider providing native packages in RPM, DEB, etc., with GPG / PGP signatures. However, they do have an official docker image.

In this scenario, I suggest copying their official image to your own private repository and installing rust using the following example.

COPY --from=${YOUR_ECR}/rust:1.62.1-bullseye /usr/local/cargo/ /usr/local/cargo/
COPY --from=${YOUR_ECR}/rust:1.62.1-bullseye /usr/local/rustup/ /usr/local/rustup/
ARG PATH="/usr/local/cargo/bin:$PATH"
ARG CARGO_HOME=/usr/local/cargo
ARG RUSTUP_HOME=/usr/local/rustup
ARG RUST_VERSION=1.62.1
ENV RUSTUP_HOME=$RUSTUP_HOME
ENV RUST_VERSION=$RUST_VERSION
ENV CARGO_HOME=$CARGO_HOME
ENV PATH=$PATH