When installing Rust toolchain in Docker, Bash `source` command doesn’t work

You have to add the sourcing inside the .bashrc.

This works:

FROM ubuntu:16.04

# Update default packages
RUN apt-get update

# Get Ubuntu packages
RUN apt-get install -y \
    build-essential \
    curl

# Update new packages
RUN apt-get update

# Get Rust
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y

RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc

EDIT

Instead of

RUN echo 'source $HOME/.cargo/env' >> $HOME/.bashrc

you can use

ENV PATH="/root/.cargo/bin:${PATH}"

which is a less bash-only solution

Leave a Comment