Automatically set docker port

1

I'm using docker to develop my web applications, but I realized that I need to run multiple projects at the same time on my machine. As these projects basically require the same containers, which are apache and mysql, whenever I start some project on my machine, I need to be changing the host port. Is there any way I can automatically set a port for the container I want to create? For example, if port 80 is already being taken up by the apache of another application, it automatically allocates another port for the application to start.

I would also like to know if there is any way I can set up the app url. for example, I currently access a project of mine through the link: localhost: 3000. Is there any way I can type in my browser meuprojeto.com.br and it directs to localhost: 3000?

    
asked by anonymous 21.06.2017 / 03:39

1 answer

1

If the Dockerfile of your project exposes a port, just docker run use -P instead of -p porta:porta so that docker allocates a valid port any dynamically at the time of creating the container.

When we are in a docker-compose, in the ports element, just set a - "porta" port instead of - "porta:porta" to have the same result.

    
22.06.2017 / 10:21