Sagar Ghuge
Sagar Ghuge

Reputation: 241

Need some help on Docker's dynamic port mapping with Host?

I have a use case where there will be multiple Docker containers running with web server. I can't bind port 80 for all containers. I am looking for a solution where I can bind container's dynamic ports to host at 80. Is it something possible with Traefik? If so, how?

I have to implement it for gitlab's review-apps. If anyone has done it before, please guide me.

Upvotes: 0

Views: 819

Answers (1)

jagatjyoti
jagatjyoti

Reputation: 717

If I understood your question, you can do it at the primitive stage itself while starting the container. Below command will bind port 80 of host to a dynamic (random) port on the container:

docker run --name <container-name> -d -p 80 <image-name>

If you are talking about knowing the dynamic ports you need to use a service discovery tool which in turn will talk to Docker API and extract the information for you.

N.B: I don't have much idea about Traefik but the above are usual ways to achieve what is asked.

Upvotes: 1

Related Questions