Referring to replica names with Docker stack deploy and nginx

I am trying to use a Docker stack with NGINX, and a web server.

  registry:
    image: registry
    ports:
      - "5000:5000"
    networks:
      - central-network
    volumes:
      - /srv/registry:/var/lib/registry
    deploy:
      placement:
        constraints: [node.hostname == prod-edge1]

  nginx:
    image: nginx
    ports:
      - "80:80"
      - "443:443"
    networks:
      - central-network
    volumes:
      - /srv/nginx:/etc/nginx
      - /srv/nginx/html:/usr/share/nginx/html
    depends_on:
      - registry
    deploy:
      placement:
        constraints: [node.hostname == prod-edge1]

I deploy it as such:

docker stack deploy -c ~/scripts/web.yml web

My nginx conf file contains:


upstream registry {
        ip_hash;
        server web_registry.1:5000;
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name foo.bar;
    location / {
        proxy_pass http://registry;
        include snippets/proxy-pass.conf;
        if ($uri != '/') {
            expires 30d;
        }
    }
}

When I deploy, nginx errors out saying it can’t hit web_registry.1.

When I console in to nginx bash, I can only ping it with web_registry.1.sdgasdgfawelkafwejfasd.

How do I resolve the stack containers so I can refer to them in my nginx config?

I had a similar issue, I resolved by using the service in my nginx conf not the container name. In your case drop the .1 and just have nginx point to http://web_registry: