Connection refused between two containers

I know this is a already seen problem but none of solutions I found worked for me.

Now, I have microservice oriented app and my containers can’t communicate between eachother. Every time I try to access a resource on some container from another container I get Connection Refused response.

If I curl container’s a resource from another container I get a Connection refused.

If I ping my host name from inside container it resolves properly.

If I curl container’s endpoint from host machine or from another computer it works fine.

They all belong to the same network project_default, I even made a new network and placed them in there but I still have the same result.

I run them from docker compose, here it is:

version: '3.4'

services:
  app.identityserver:
    image: registry.digitalocean.com/myrepo/appidentityserver:latest
    build:
      context: .
      dockerfile: App.IdentityServer/Dockerfile
    ports:
        #- 6003:5003
        - 6004:443
        #- 6005:80
    container_name: appidentityserver
    environment:
        - ApiUrl=https://dev.mydomain.net:6000
        - ChatHubApiUrl=https://dev.mydomain.net:6100
        - MediaServerPath=https://dev.mydomain.net:6200
        - MailServiceUrl=https://dev.mydomain.net:6300
        - DefaultConnection=
        - ASPNETCORE_ENVIRONMENT=Development
        - ASPNETCORE_URLS=https://+;http://+
        - ASPNETCORE_HTTPS_PORT=6004
        - ASPNETCORE_Kestrel__Certificates__Default__Path=/app/sslCert/archive/cert1.pem
        - ASPNETCORE_Kestrel__Certificates__Default__KeyPath=/app/sslCert/archive/privkey1.pem
    volumes:
        - /etc/letsencrypt/archive/dev.mydomain.net/:/app/sslCert/archive/
    networks:
        - local

  app.api:
    image: registry.digitalocean.com/repo/appapi:latest
    build:
      context: .
      dockerfile: App/Dockerfile
    ports:
        - 6000:443
        #- 6001:80
    container_name: yekkaapi
    environment:
        - IedntityServerUrl=http://dev.mydomain.net:6004
        - DefaultConnection=
        - ChatHubPath=https://dev.mydomain.net:6100
        - MediaServerPath=https://dev.mydomain.net:6200
        - MailServicePath=https://dev.mydomain.net:6300
        - ASPNETCORE_ENVIRONMENT=Development
        - ASPNETCORE_URLS=https://+;http://+
        - ASPNETCORE_HTTPS_PORT=6000
        - ASPNETCORE_Kestrel__Certificates__Default__Path=/app/sslCert/archive/cert1.pem
        - ASPNETCORE_Kestrel__Certificates__Default__KeyPath=/app/sslCert/archive/privkey1.pem
    volumes:
        - /etc/letsencrypt/archive/dev.mydomain.net/:/app/sslCert/archive/
    depends_on:
        - app.identityserver
    networks:
        - local


What were those solutions?

How do you do that?

Can you explain why do you expect it to work? I am not an ASP.NET developer so I am not sure what part of the code sets the listening port inside the container. For internal communication you should use the containers’ internal ports and internal IP addresses or domain names. If you don’t do that a firewall (or maybe SELinux?? / Apparmor??) can prevent the containers from accessing the external IP address of the host.