Search code examples
amazon-web-servicesdockerdockerfileamazon-ecs

Pass environment variable values inside Dockerfile


I am using environment variables under my ECS task def which pull values. The variable name is say encryptor.password I have this also declared in my Dockerfile as ENV variable with some dummy value but at the same time is called at a later entrypoint section something like below :-

ARG pwd
ENV encryptor.password $pwd
# Run the app.jar using the recommended flags per
# https://spring.io/guides/gs/spring-boot-docker/#_containerize_it
ENTRYPOINT ["java","-Dhttp.proxyHost=***",\
"-Dhttps.proxyHost=***","-Dhttp.proxyPort=***",\
"-Dhttps.proxyPort=***","-Djava.net.useSystemProxies=true",\
"-Dhttp.nonProxyHosts=***|/var/run/docker.sock|***|***|***",\
"-Djava.security.egd=file:/dev/./urandom","-Dencryptor.password=${encryptor.password}","-Dspring.profiles.active=dev",\
"-jar","/app/app.jar"]

My understanding is that -Dencryptor.password=${encryptor.password} should actually be replaced by the value that is coming to this dockerfile for the ENV variable encryptor.password from the taskdef when the container starts, but looks like the entrypoint is not picking that value. Am i missing something. How to get Dockerfile to get that value?


Solution

  • The issue was that you need to firstly use shell form of ENTRYPOINT so either have an entrypoint.sh script where you define your commands and arguments and then execute in shell form from ENTRYPOINT or else pass everything as :-

    ENTRYPOINT ["sh", "-c", "java ........."]

    At the same time make sure the variables parsed in ENTRYPOINT for shell do not use dots. Dots are not valid shell identifiers and very commonly overlooked.