I have a docker-compose.yml
file in one of my projects where I link multiple containers to build one application. The main entry point (i.e. a container with a web server) is run on host port 8080
.
Now this port is hard-coded into the docker-compose.yml
file.
Is there a way to dynamically set this port using runtime parameters? I could not find anything on this in the documentation, but on the other hand I can not imagine that this should not be possible.
Is it?
Ports is defined as:Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen). Ports mentioned in docker-compose. yml will be shared among different services started by the docker-compose. Ports will be exposed to the host machine to a random port or a given port.
Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .
This question is super old, but it's been viewed a bunch of times so I'll post the link to the docs for using environment variables:
https://docs.docker.com/compose/environment-variables/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With