简体   繁体   English

尝试在 docker(github 代码空间)上安装 asdf 插件时权限被拒绝

[英]Permission denied when trying to install asdf plugin on docker (github codespace)

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 上有一些脚本,旨在将asdf的插件 ruby​​ 插件安装在Github 代码空间的客户容器上(使用 devcontainer.json、docker-compose、dockerfile ...)。

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我敢肯定,因为如果我只运行上面的这个 RUN 时钟,我可以构建我的 github 代码空间而不会出现任何错误,而且我也确定 asdf 确实安装了,因为我通过命令终端检查它

$ sudo su
$ asdf list

This outputs a message from asdf, showing it did install:这会从 asdf 输出一条消息,显示它确实安装了:

no plusins installed

But the second part below, where i try to install asdf's ruby plugin, gets an error:但是下面的第二部分,我尝试安装 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

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:我为这个 RUN 块的第一行尝试了不同的东西,但我总是遇到某种错误:

If I do RUN sudo $HOME/.bashrc , I got the error如果我RUN sudo $HOME/.bashrc ,我得到了错误

sudo: /root/.bashrc: command not found

If I do RUN sudo su $HOME/.bashrc , I got the error:如果我执行RUN sudo su $HOME/.bashrc ,我会收到错误消息:

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:如果我RUN su vscode $HOME/.bashrc ,我得到了错误:

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我是 docker 的非常早期的初学者,所以我找不到如何绕过这个并安装 ruby​​ 插件

The second RUN should be like this:第二次 RUN 应该是这样的:

RUN bash -c "source $HOME/.bashrc  && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby RUBY_VERSION && asdf global ruby $RUBY_VERSION"

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以将其应用于所有剩余命令。

.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. .bashrc是每次您登录(打开终端)时运行的文件/脚本,您不能像手动运行任何其他脚本一样运行它。

You can try something like this RUN exec $HOME/.bashrc or RUN source $HOME/.bashrc instead just running it like any other script.您可以尝试类似这样的RUN exec $HOME/.bashrcRUN source $HOME/.bashrc ,而不是像任何其他脚本一样运行它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM