My Dockerfile sets some defaults for environment variables, then later exposes two ports that should be the provided environment variables:
FROM python:3.6.5-stretch
[ ... ]
ENV MY_SERVICE_PORT 8080
ENV MY_SERVICE_PORT_RPC 50051
[ ... ]
EXPOSE ${MY_SERVICE_PORT}
EXPOSE ${MY_SERVICE_PORT_RPC}
My application inside the container reads the environment variable correctly when starting the container. If I run my image using:
docker run -e "MY_SERVICE_PORT=80" -d -t image_tag
Then I use docker ps:
0fb14e12d43d image_tag "/bin/sh -c 'python3…" 8080/tcp, 50051/tcp
As you can see, EXPOSE used the build-time environment variables (defaulting to 8080 and 50051). If I execute set inside the container terminal, I get:
MY_SERVICE_PORT=80
MY_SERVICE_PORT_RPC=50051
How can I make sure EXPOSE is only set to a run-time environment variable? Is it possible?