Docker compose variables Docker compose variables docker docker

Docker compose variables


Docker-compose resolves variables in the compose file from the environment where you run the docker-compose command, not from inside the container. If you want to configure your environment from inside the container, you'll need to add this to the command or entrypoint your container runs. If you don't already have an entrypoint, you could create one as:

#!/bin/shexport VAR2=${HOSTNAME}_${VAR1}exec "$@"

To use that, your Dockerfile would then have two extra lines:

COPY entrypoint.sh /entrypoint.shENTRYPOINT ["/entrypoint.sh"]

Make sure to chmod 755 entrypoint.sh before running your docker build.


Edit: VAR1 not resolving inside your yml is a similar issue. Each variable is defined by docker-compose for the container, but that doesn't change the environment on the host that docker-compose is using. So you can't use that variable on later lines of the yml.