Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Permission denied when trying to edit .bashrc in a container

Trying to run the command below:

docker container exec container-name echo '. $HOME/.asdf/asdf.sh' >> /root/.bashrc

but I’m getting the error below:

warning: An error occurred while redirecting file '/root/.bashrc'
open: Permission denied

I just created the container.
I can get into the container as root and execute the same command without error.
Does anybody know what I’m missing?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are trying to write in your host’s root user .bashrc. It is good that you didn’t run this as user root on host.

I think this is what you actually want:

docker container exec container-name sh -c 'echo . $HOME/.asdf/asdf.sh >> /root/.bashrc'

Also you can use /root instead of $HOME since you already use that in the second part of the command.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading