TYX
TYX

Reputation: 53

Docker environment variables not pass correctly

My Docker image (CentOS 7) runs a bash script which expects some environment variables. The bash script is started via the ENTRYPOINT directive.

# Inside the Dockerfile
ADD run.sh .
RUN chmod 777 run.sh
ENTRYPOINT ["/bin/bash", "-c", "./run.sh"]

# Inside run.sh
echo MakeDir: $MakeDir

To start this container, I run the following command:

docker run -t myimage -e MakeDir=/path/to/something

Unfortunately, the run.sh script cannot see the MakeDir environment variable. What am I doing wrong? Any help would be greatly appreciated.

Upvotes: 2

Views: 1795

Answers (1)

chepner
chepner

Reputation: 530960

Arguments after the image are passed to (and in this case, ignored by) the command, not docker run. Put -e before the image.

docker run -t -e MakeDir=/path/to/something myimage

Upvotes: 5

Related Questions