Updating PATH environment variable permanently in Docker container

前端 未结 4 1629
北荒
北荒 2020-12-12 23:41

I tried adding to the PATH in the files ~/.profile and /etc/profile as follow.

PATH = $PATH:/required/path


        
相关标签:
4条回答
  • 2020-12-13 00:02

    1. The correct answer

    The best voted answer suggests to add ENV PATH "$PATH:/new/path" to the Dockerfile, and this should indeed work.

    2. So why doesn't it work for me?

    As noted in some comments/answers, the solution 1. does not work for some people.

    The reason is that the PATH can be overwritten by some script like .bashrc when running the docker container, giving thus the impression that the ENV PATH... did not work, but it theoretically did.

    To solve the issue, you need to append to the .bashrc the correct PATH by adding the below command to your Dockerfile:

    RUN echo "export PATH=/new/path:${PATH}" >> /root/.bashrc

    0 讨论(0)
  • 2020-12-13 00:07

    I got the answer for this question in irc chat. Given here for the benefit of anyone who may come across this. Many people have given wrong answers as update the ~/.profile but that did not work. So use the answer below.

    Update the file ~/.bashrc for user or update the file /etc/enviroment global for global change which will apply for all users.

    In .bashrc export PATH: export PATH=$PATH:/new/path/bin

    In enviroment: PATH=$PATH:/new/path/bin

    0 讨论(0)
  • 2020-12-13 00:13

    If you want to include a /new/path in the Dockerfile, adding the line:

    ENV PATH "$PATH:/new/path"

    in Dockerfile should work.

    0 讨论(0)
  • 2020-12-13 00:13

    Put in your Dockerfile a line ENV PATH xxx see an example in this Dockerfile https://gist.github.com/deepak/5933685

    0 讨论(0)
提交回复
热议问题