我在dockerfile上有一些脚本,旨在安装 asdf github codespace的custome容器(使用devcontainer.json,docker-compose,dockerfile ...)。
Dockerfile:
RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/completions/asdf.bash' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile
第一部分正常工作。我敢肯定,因为如果我仅在上面运行时钟运行时钟,我可以构建我的github codespace而没有任何错误,并且我也确定ASDF确实安装了,因为我通过命令终端对其进行了检查
$ sudo su
$ asdf list
,这将输出来自ASDF的消息,显示它确实确实如此安装:
no plusins installed
但是下面的第二部分(我尝试安装ASDF的Ruby插件)会出现一个错误:
RUN $HOME/.bashrc && \
# install asdf ruby plugin
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && \
# add ruby version
asdf install ruby $RUBY_VERSION && \
# set our machine e.g our container's global Ruby version
asdf global ruby $RUBY_VERSION
我遇到的错误是:
/bin/sh: 1: /root/.bashrc: Permission denied
对于错误输出的较大上下文,命令输出的终端显示:
#6 [ 3/11] RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && echo '. $HOME/.asdf/completions/asdf.bash' >> $HOME/.bashrc && echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile
#6 0.746 Cloning into '/root/.asdf'...
#6 DONE 1.6s
#7 [ 4/11] RUN $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby latest && asdf global ruby latest
#7 0.658 /bin/sh: 1: /root/.bashrc: Permission denied
#7 ERROR: executor failed running [/bin/sh -c $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby $RUBY_VERSION && asdf global ruby $RUBY_VERSION]: exit code: 126
我尝试了第一个的不同事物此运行块的行,但是我总是会遇到某种错误:
sudo $ home/.bashrc ,我会遇到错误
sudo: /root/.bashrc: command not found
如果我运行 .bashrc
,我遇到了错误:
su: user /root/.bashrc does not exist or the user entry does not contain all the required fields
如果我做运行su vscode $ home/.bashrc
,我有错误:
bash: /root/.bashrc: Permission denied
我在Docker上很早就很早,所以我找不到如何绕过此并安装Ruby插件
I have some script on a dockerfile that is aimed at installing the asdf's plugin ruby plugin on a Github codespace's custome container (using devcontainer.json, docker-compose, a dockerfile...).
Dockerfile:
RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/completions/asdf.bash' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile
This first part works correctly. I'm sure because if I run just this RUN clock above, I can build my github codespace without any error and I'm also sure asdf did install because I check it via terminal of command
$ sudo su
$ asdf list
This outputs a message from asdf, showing it did install:
no plusins installed
But the second part below, where i try to install asdf's ruby plugin, gets an error:
RUN $HOME/.bashrc && \
# install asdf ruby plugin
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && \
# add ruby version
asdf install ruby $RUBY_VERSION && \
# set our machine e.g our container's global Ruby version
asdf global ruby $RUBY_VERSION
The error I get is:
/bin/sh: 1: /root/.bashrc: Permission denied
For a larger context on the error output, the terminal of command output shows:
#6 [ 3/11] RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && echo '. $HOME/.asdf/completions/asdf.bash' >> $HOME/.bashrc && echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile
#6 0.746 Cloning into '/root/.asdf'...
#6 DONE 1.6s
#7 [ 4/11] RUN $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby latest && asdf global ruby latest
#7 0.658 /bin/sh: 1: /root/.bashrc: Permission denied
#7 ERROR: executor failed running [/bin/sh -c $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby $RUBY_VERSION && asdf global ruby $RUBY_VERSION]: exit code: 126
I tried different things for the first line of this RUN block, but I always run into some sorts of error:
If I do RUN sudo $HOME/.bashrc
, I got the error
sudo: /root/.bashrc: command not found
If I do RUN sudo su $HOME/.bashrc
, I got the error:
su: user /root/.bashrc does not exist or the user entry does not contain all the required fields
If i do RUN su vscode $HOME/.bashrc
, I got the error:
bash: /root/.bashrc: Permission denied
I'm very very early beginner on docker so I could not find how to bypass this and install ruby plugin
发布评论
评论(2)
第二轮应该是这样的:
是的,这很丑陋,但老实说,我不知道是否可以安全地分解线条。
关键是您必须 source 您的.bashrc才能将其应用于所有其余命令。
The second RUN should be like this:
Yeah, it's ugly, but honestly I do not know if it's safe to break up to lines.
The key is you have to source your .bashrc to apply it to all remaining commands.
.bashrc
是每次登录(打开终端)时运行的文件/脚本,您无法像手动一样运行它。您可以尝试类似
运行exec $ home/.bashrc
运行源$ home/.bashrc 而不是像其他任何脚本一样运行它。.bashrc
is file/script that is run every time you log in (open your terminal) and you can not run it like any other script manually.You can try something like this
RUN exec $HOME/.bashrc
orRUN source $HOME/.bashrc
instead just running it like any other script.