I want to pass environment variables in my docker run
command and access them in my entrypoint shell script.
This is my super simple Dockerfile
for test purposes:
FROM ubuntu:20.04
WORKDIR /
ADD entrypoint.sh .
RUN chmod 755 entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
And this is the entrypoint.sh
:
#!/bin/sh
printf "env var TEST = ${TEST} "
I just build the Dockerfile
like this: docker build -t test:1.0 .
And then run it like this: docker run -i test:1.0 -e TEST='Hello world'
Unfortunately the output is not containing the env var.
2
Answers
Something like this will work:
entrypoint.sh
Dockerfile
And then you can build & run the container while setting the environment variable with:
For the record: Predefining the variables is not the solution.
The order of the args is important, like David Maze said.