I am trying to create a docker image that will setup a Linux environment for building Rust projects. Here is my Dockerfile
so far:
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
The last thing I need to do is configure Rust, so that I can use cargo
. The documentation says to use
source $HOME/.cargo/env
but when I try that in a RUN
command in a Dockerfile, it says source
is not recognized. Another option I found was to use
RUN /bin/bash -c "source ~/.cargo/env"
This does not error, but when I run my container, cargo
is not a recognized command.
Either approach works from Bash when I have the container open, but I would like this to be automated as part of the image.
How can I integrate this into my Dockerfile?
bash -c 'source anything'
onlysource
s a file into that singlebash
instance, which exits when the command completes. The right way to use it isbash -c 'source ~/.cargo/env && cargo whatever'
, running thesource
in the same shell that actually needs to use what you're adding..
instead ofsource
-- the latter name is a bashism, whereas the former is POSIX-mandated).