# Connection refused between two containers

**URL:** <https://forums.docker.com/t/connection-refused-between-two-containers/128552>\
**Category:** Compose\
**Tags:** docker, docker-compose\
**Created:** [September 3, 2022, 2:45pm UTC](https://forums.docker.com/t/connection-refused-between-two-containers/128552 "2022-09-03T14:45:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jetisumadinac](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/jetisumadinac/32/32611_2.png) [@jetisumadinac](https://forums.docker.com/u/jetisumadinac)\
**Post date:** [September 3, 2022, 2:45pm UTC](https://forums.docker.com/t/connection-refused-between-two-containers/128552/1 "2022-09-03T14:45:10Z")

</div>

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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![rimelek](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/rimelek/32/41602_2.png) [@rimelek](https://forums.docker.com/u/rimelek)\
**Post date:** [September 4, 2022, 9:21am UTC](https://forums.docker.com/t/connection-refused-between-two-containers/128552/2 "2022-09-04T09:21:19Z")

</div>

> [@jetisumadinac](#):
>
> I know this is a already seen problem but none of solutions I found worked for me.

What were those solutions?

> [@jetisumadinac](#):
>
> If I curl container’s endpoint from host machine or from another computer it works fine.

How do you do that?

Can you explain why do you expect it to work? I am not an [ASP.NET](http://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.
