skip to Main Content

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

Answers


  1. .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 or RUN source $HOME/.bashrc instead just running it like any other script.

    Login or Signup to reply.
  2. The second RUN should be like this:

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search