问题描述
我正在尝试创建一个泊坞窗映像,该映像将设置Linux环境以构建Rust项目。这是到目前为止我的 Dockerfile
:
从ubuntu:16.04
#更新默认软件包
运行apt-get更新
#获取Ubuntu软件包
运行apt-get install -y \
build-基本\
curl
#更新新软件包
RUN apt-get update
#获取Rust
RUN curl https:// sh.rustup.rs -sSf | bash -s--y
我最后要做的就是配置Rust,这样我可以使用货物
。该文档说使用
source $ HOME / .cargo / env
但是当我在Dockerfile的 RUN
命令中尝试使用此命令时,它显示为来源
无法识别。我发现的另一个选择是使用
RUN / bin / bash -c源〜/ .cargo / env
这不会出错,但是当我运行集装箱时,货物
不是公认的命令。
打开容器后,这两种方法都可以从Bash使用,但是我希望将其作为图像的一部分自动实现。 / p>
如何将其集成到我的Dockerfile中?
这可行:
从ubuntu:16.04
#更新默认软件包
RUN apt-get更新
#获取Ubuntu软件包
RUN apt-get install -y \ build
构建必备项\
curl
#更新新软件包
运行apt-get update
#获取Rust
运行curl https://sh.rustup.rs -sSf | bash -s--y
RUN echo'source $ HOME / .cargo / env'>> $ HOME / .bashrc
编辑
代替
RUN echo'source $ HOME / .cargo / env'>> $ HOME / .bashrc
您可以使用
ENV PATH = / root / .cargo / bin:$ {PATH}
这是一种不那么扑朔迷离的解决方案
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?
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
这篇关于在Docker中安装Rust工具链时,Bash`source`命令不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!