0

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?

ki9
  • 1,169
  • 1
  • 10
  • 18

1 Answers1

0

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:*
ki9
  • 1,169
  • 1
  • 10
  • 18