0

I have a dockerfile that declares some environment variables that are being used later in the entrypoint, but the entrypoint never picks up the values for those variables. I tried the shell form but looks like its not doing anything. Here is my sample dockerfile :-

FROM java:8
ENV JAVA_OPTS="
RUN apt-get -y install ca-certificates curl
RUN mkdir /app
RUN mkdir /docker
CMD ["java", "-version"]
ADD /target/app.jar /app/app.jar
ENV spring.profiles.active dev
ENV encryptor.password xyz
COPY entrypoint.sh /docker/entrypoint.sh
RUN ["chmod", "+x", "/docker/entrypoint.sh"]
EXPOSE 8080
ENTRYPOINT ["/bin/bash", "-c", "/docker/entrypoint.sh"]
CMD ""

My entrypoint.sh is very simple and uses these ENV variables :-

#!/bin/bash
java -Djava.security.egd="file:/dev/./urandom" -Dencryptor.password=$encryptor.password -Dspring.profiles.active=$spring.profiles.active -jar /app/app.jar

How should i make my ENTRYPOINT to be able to access those ENV variables declared earlier in the Dockerfile so that its able to assign appropriate values to the arguments passed in. Went through several posts and stuffs on the internet and tried lot of ways to get this work, but didn't seem to work a single time.

Ashley
  • 1,447
  • 3
  • 26
  • 52

1 Answers1

3

I think an issue is the periods (dots) within the environment variable names. I think, valid identifiers may only include alphanumeric characters and underscores.

You will also need to use the shell form of ENTRYPOINT to get a shell that can do environment variable substitution:

FROM busybox

ENV spring_profiles_active dev
ENV encryptor_password xyz

ENTRYPOINT echo ${spring_profiles_active} ${encryptor_password}

Then:

docker build --tag=example --file=./Dockerfile .
docker run --interactive --tty example

Returns:

dev xyz
DazWilkin
  • 32,823
  • 5
  • 47
  • 88