Docker Community Forums

Share and learn in the Docker community.

Reverse proxy for same port multiple containers

(Canadagoose) #1

I have been trying to search on the web about this and do it but I have been confused about how to go about doing this.

So, i want to set up two docker applications (Confluence and BitBucket) to run on the same port (80). Now the way to do this as I understand is to use a reverse proxy using nginx. I still have not figured out exactly how to do this. If anyone has ideas or instructions, it would be very much appreciated.


(Raj Chaudhuri) #2

Try this image:

(Archimedes Trajano) #3

I use nginx myself but there’s a new project called that seems to do a better job and only does reverse proxy.

(Canadagoose) #4

I tried using their run command to install their nginx-proxy and then I ran:

sudo docker run -v /data/your-confluence-home:/var/atlassian/application-data/confluence --name=“confluence” -d --expose=80 -p 8090:8090 -p 8091:8091 -e atlassian/confluence-server

Unfortunately I don’t know how DNS forwarding works so how will I access

in fact if I try to access my ip address (default port 80) it gives me nginx Error 503.

Any ideas? Thanks

(Raj Chaudhuri) #5

Hi, sorry about the delayed response.

nginx-proxy allows you to reach multiple containers through a single proxy container, using host headers. This means that you have to use a hostname like to make the request. This request will reach the nginx-proxy container, which will then match the hostname to another container, and route the request to that.

So, the steps you need to carry out (in order) are as follows:

  1. Start an nginx-proxy container, and map its port 80 to the host port 80
  2. Start your application containers, each with a environment variable VIRTUAL_HOST containing the hostname you want that container to be identified by, and another variable called VIRTUAL_PORT containing the port on that container you want to reach.
  3. Ensure that all the names that you used in the VIRTUAL_HOST variables resolve to the IP address of the docker host. For development/testing, you can do this by making entries in the hosts file on the docker host.
  4. Access your application using the relevant hostname.

In your case, as far as I can tell, the commands would be:

Step 1.
docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
Note that port 80 of the host is mapped to port 80 of the nginx-proxy container.

Step 2.
docker run -v /data/your-confluence-home:/var/atlassian/application-data/confluence --name=“confluence” -d -e -e VIRTUAL_PORT=8090 atlassian/confluence-server
Note that no ports are mapped for this; i.e., no -p is required.

Step 3.
This would depend on which operating system you use. If on linux, edit the file /etc/hosts to add the following line. If on Windows, edit the file %windir%\system32\drivers\etc\hosts to add the following line: <ip address of docker host>

Step 4.
Make a requerst to, which should resolve to your ip address (default port 80). You should correctly reach the confluence container on port 8090.

(Raj Chaudhuri) #6

Yes, Traefik is awesome!