Docker Community Forums

Share and learn in the Docker community.

Problem with NGINX, network and services

Hi everyone,
today I started to setup a new NGINX container I want to use as a reverse proxy for the containers on my RasperryPi.
In order to test NGINX features, I created a limitated set of containers.
I created 3 docker-compose files, one for NGINX and the other two are for two different services of Transmission (the torrent client). All the containers use the same network I created before. I gave to every every container a different container_name and a different alias in the networks section.

After I finished my setup, I run the docker-compose up and tried to go to the Transmission web GUI using the DNS name I setted but I’m always redirect to the first container I got up. If I try to reach the GUI using IP:PORT, I’m able to open the right container so they are both up&running.

Here I post a snippet from the Transmission docker-compose:

File #1
version: “3.7”
services:
transmission:
build: ./transmission
container_name: transmission
networks:
trans_network:
aliases:
- transmission

File #2
version: “3.7”
services:
transmission:
build: ./transmission
container_name: transmission2
networks:
trans_network:
aliases:
- transmission2

As you can see, container name and network alias are different.
After I found out this solution isn’t working, I tried to change the service name, so I changed the service name in File #2 from “transmission” into “transmission2”.
I rebuild my containers and run the docker-compose up and everything just worked fine.

I searched in the documentation and in different forums but I didn’t find out anything useful to understand what is the problem. In the articles I followed to setup my environment I always read that the thing that has to be different is the container name and not the service name.

From what I see, I can suppose that I can’t have different services with the same name in the same network because something is in conflict, probably because of the same name.
Can someone help me to understand? Probably I miss something about networks and services because of my limited experience and I would like to understand better this behaviour.

Thank you in advanced.

Alessandro

A service is registered by its service name and if present by its container name and network alias. You ended up creating not unique dns entries.

Hi Meyay,
thanks for your reply. I setted both container name and network alias so if I correctly understood what you said should be this two that define the DNS name. In the .conf NGNIX I definined http://transmission:9091/ and http://transmission2:9091/, using the value I setted for container_name and alias.

The service name is always used as dns name! Container name and/or network aliases are set as additional dns names if present… Make sure your service names and network aliases do no collide between different services (or instances).

1 Like

Oh now I get it! So the service name is the primary DNS name while the others are just additional entries.
So, to resume, it’s not totally correct the fact that the container name is the one you should be add to the .conf: I mean, you can do that but in any case you have also to pay attention to the service names that are the ones who really matter because they are always use as DNS name.
Thank you very much for you explanation!

yep

Actualy all of the names will be resolved… Your main problem was that your service names and one of the aliases have been identical. It is okay to use identical service names, as long as you use different network aliases for them and use the network aliases as reverse proxy target. Honestly, I don’t know how the precedence is amongst service name, container name, host name and network alias - I never brought my self in a situation where this would be of importance.

Ok, I’ve understood that the problem is the fact I have the same name as service name and alias.
I’ve tried to change the alises in something different and I’ve done the same change in the NGINX .conf and it seems it’s working, so in this case the alias has higher priority then service name.
Thank you very much for your help.