Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the port for docker-compose.yml at runtime

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?

like image 314
Golo Roden Avatar asked May 26 '15 04:05

Golo Roden


People also ask

What is ports in Docker compose yml?

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.

Does docker use port 8080?

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 .


1 Answers

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/

like image 166
Troy Kelley Avatar answered Oct 08 '22 16:10

Troy Kelley