Score:0

Multiple webserver docker containers listening on different host IPs

kz flag

I have a server with multiple IP addresses. I want different nginx containers to listen on :80 and :443 on two IPs on this host.

/srv/www1/docker-compose.yml:

nginx:
  image: nginx:mainline-alpine
  container_name: www1
  ports:
    - "69.69.69.1:80:80/tcp"
    - "69.69.69.1:443:443/tcp"

/srv/www2/docker-compose.yml:

nginx:
  image: nginx:mainline-alpine
  container_name: www2
  ports:
    - "69.69.69.2:80:80/tcp"
    - "69.69.69.2:443:443/tcp"

Either container can start first without problems, but if I try to start the second container (www2 for example), while the first is already running, the first container is stopped and this error is thrown:

WARNING: Found orphan containers (www1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.

No, they are not the same container- the docker-compose.yml files are not even in the same directory. It seems like docker uses the image: and ports: fields to identify containers, but ignores the IP addresses.

Is this a bug? How can I make it work?

Score:0
kz flag

Running the containers from a single docker-compose file is working.

/srv/www/docker-compose.yml:

version: '3'
services:

    nginx1:
      image: nginx:mainline-alpine
      container_name: www1
      ports:
        - "69.69.69.1:80:80/tcp"
        - "69.69.69.1:443:443/tcp"
    
    nginx2:
      image: nginx:mainline-alpine
      container_name: www2
      ports:
        - "69.69.69.2:80:80/tcp"
        - "69.69.69.2:443:443/tcp"

Check it with ss:

# ss -tln | grep ':80 \|:443 '
LISTEN 0      4096           69.69.69.1:443        0.0.0.0:*          
LISTEN 0      4096           69.69.69.2:443        0.0.0.0:*          
LISTEN 0      4096           69.69.69.1:80         0.0.0.0:*          
LISTEN 0      4096           69.69.69.2:80         0.0.0.0:*
in flag
Is this supposed to be the solution? It sounds like more information that should be edited into the question instead.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.