I have a base image which exports a number of variables in it's ENTRYPOINT shell script docker-entry.sh.

Now I'm consuming the base image and running CMD with a mongo-entry.sh. I was hoping to access the variables exported from the ENTRYPOINT in the mongo-entry.sh.

I'm able to see the the log statements with the variables from docker-entry.sh being printed out, but, I'm unable to access it in mongo-entry.sh

I've already tried calling the docker-entry.sh and mongo-entry.sh as ENTRYPOINT in my DockerFile


Base Image ENTRYPOINT docker-entry.sh

 export var1 = "var1"

Current image

FROM 'baseimage'
COPY ["mongo-entry.sh"]
CMD ["mongo-entry.sh"]


echo "var1=$VAR1"



1 Answers

DazWilkin On Best Solutions

I suspect there are 1-2 issues:

  1. ENTRYPOINT and CMD aren't inherited from the FROM image
  2. You may be using the exec form of ENTRYPOINT|CMD

There are 2 forms of ENTRYPOINT and CMD, the shell and exec forms. The exec form "does not invoke a command shell" and so you won't get environment variable processing:


Here's an example which shows ENV values passing through FROM'd images:

echo '
FROM bash
ENV DOG=Freddie
ENTRYPOINT echo "dog=${DOG}"
' | docker build --tag=1st --file=- .
echo '
FROM 1st
ENV CAT=Emmett
ENTRYPOINT echo "dog=${DOG}" "cat=${CAT}"
' | docker build --tag=2nd --file=- .
docker run 1st
docker run 2nd

Results in:

dog=Freddie cat=Emmett

NB ${DOG} (and its value) is inherited from 1st