Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I append to PATH environment variable when running a Docker container?

Tags:

docker

I want to mount a volume and add it to the container's PATH environment variable. I've tried the following and none is working.

docker run -it -v $(PWD):/app -e PATH=$PATH:/app/bin debian:jessie bash
docker run -it -v $(PWD):/app -e PATH='$PATH:/app/bin' debian:jessie bash
docker run -it -v $(PWD):/app -e PATH='$$PATH:/app/bin' debian:jessie bash
docker run -it -v $(PWD):/app -e PATH='\$PATH:/app/bin' debian:jessie bash

How do I append the mounted volume to PATH?

like image 629
flowfree Avatar asked May 17 '16 16:05

flowfree


People also ask

How do I pass environment variables to docker containers?

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' ...

How do I add items to my PATH environment variable?

To add a path to the PATH environment variable In the System dialog box, click Advanced system settings. On the Advanced tab of the System Properties dialog box, click Environment Variables. In the System Variables box of the Environment Variables dialog box, scroll to Path and select it.

How do I set an environment variable on an existing container?

How to set the Environment variable in the container? 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.

How do I specify a Dockerfile path?

By default the docker build command will look for a Dockerfile at the root of the build context. The -f , --file , option lets you specify the path to an alternative file to use instead. This is useful in cases where the same set of files are used for multiple builds.


1 Answers

If you you use -e option, the $PATH value is the PATH of the host instead of the container.

You can do it like this:

docker run -it -v $(PWD):/app debian:jessie bash -c 'export PATH=$PATH:/app/bin; bash'
like image 181
KiwenLau Avatar answered Sep 28 '22 09:09

KiwenLau