I tried adding to the PATH
in the files ~/.profile
and /etc/profile
as follow.
PATH = $PATH:/required/path
However, it does not work. Then I tried with adding the line show, which did not work either.
export PATH
It did not work even after restarting the container and the host both.
To set an environment variable you should use flag -e while using docker run or docker-compose command. Environment file - If the environment variable is not overridden by docker-compose. yml, shell environment the variable then the environment file will get the precedence.
With a Command Line Argument The command used to launch Docker containers, docker run , accepts ENV variables as arguments. Simply run it with the -e flag, shorthand for --env , and pass in the key=value pair: sudo docker run -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='password' ...
If you want to make changes inside the container and want those changes to persist, you can use the Docker commit command. This will create a new image with all the changes made to the previous container committed to it.
If you want to include a /new/path
in the Dockerfile, adding the line:
ENV PATH "$PATH:/new/path"
in Dockerfile should work.
The best voted answer suggests to add ENV PATH "$PATH:/new/path"
to the Dockerfile, and this should indeed work.
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
Put in your Dockerfile a line ENV PATH xxx
see an example in this Dockerfile https://gist.github.com/deepak/5933685
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With