Connection refused on API request between containers with docker compose

I am having a similar issue with nginx-proxy. The proxy works, and i can access the api and the ui separately from a client. But I cannot access the api from the ui.

I have two sites with subdomains: api .example. com and ui. example. com. I navigate to ui. example. com, and get the main page, but the call to api. example. com returns System.Net.Sockets.SocketException (111): Connection refused

Docker compose file:

version: '2'  

services:  

nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
  - '80:80'
  - '443:443'
volumes:
  - '/etc/nginx/vhost.d'
  - '/usr/share/nginx/html'
  - '/etc/nginx/certs:/etc/nginx/certs:ro' 
  - '/var/run/docker.sock:/tmp/docker.sock:ro'


letsencrypt-nginx-proxy:
container_name: letsencrypt-nginx-proxy
image: 'jrcs/letsencrypt-nginx-proxy-companion'
volumes:
  - '/etc/nginx/certs:/etc/nginx/certs'
  - '/var/run/docker.sock:/var/run/docker.sock:ro'
volumes_from:
  - nginx-proxy


 api.example.com:
environment:
  - LETSENCRYPT_HOST=api.example.com
  - LETSENCRYPT_EMAIL=development@scottrassbach.net
  - VIRTUAL_HOST=api.example.com
  - ASPNETCORE_ENVIRONMENT=Development
container_name: api.example.com
restart: always
image: srassbach/exampleapi:latest
expose: 
  - 80
  - 443


ui.example.com:
environment:
  - LETSENCRYPT_HOST=office.example.com
  - LETSENCRYPT_EMAIL=development@scottrassbach.net
  - VIRTUAL_HOST=office.example.com
  - ASPNETCORE_ENVIRONMENT=Development
restart: always
container_name: office.example.com
image: srassbach/example_ui:latest
expose:
  - 80
  - 443


www.example.com:
environment:
  - LETSENCRYPT_HOST=www.example.com
  - LETSENCRYPT_EMAIL=development@scottrassbach.net
  - VIRTUAL_HOST=www.example.com
  - ASPNETCORE_ENVIRONMENT=Production
restart: always
container_name: www.example.com
image: srassbach/example_landing:latest
expose:
  - 80


networks:  

default:
    external:
      name: nginx-net
1 Like