I am trying to run a docker container via the docker run command. I am specifying an environment variable via the -e flag. The strange thing is that I am able to read that environment variable if I exec /bin/bash into the container, but not in the entrypoint script as defined in the Dockerfile.
My docker container has debian:9 as the base and the entrypoint script is a simple bash script that logs some data along with the environment variable.
Dockerfile:
FROM debian:9
RUN apt-get update && apt-get install -y curl sudo supervisor wget
ADD starter-service.sh .
RUN chmod 755 starter-service.sh
ENTRYPOINT ["sudo", "/bin/bash", "-c", "./starter-service.sh"]
starter-service:
#! /bin/bash
license=$LICENSE_KEY
if [ "$license" == "" ]
then
echo "No License Key: "$LICENSE_KEY" arg:"$arg > /tmp/my-service.log
printenv >> /tmp/my-service.log
fi
sleep 1000s
The environment variable in question is LICENSE_KEY. Docker run command:
docker run -e LICENSE_KEY=123 <docker image>
The environment variable is not visible in the starter-service script.
p.s: also posted on stackoverflow (linux - Environment variable passed through -e flag in docker container not accessible in entrypoint script - Stack Overflow)