Search code examples
dockerdocker-composedocker-network

Why container can't request to another?


I can't send http query from container to another

I already try create network but it isn't helped

version: '2'
services:
 backend:
    container_name: backend
    image: registry.gitlab.com/myproject/backend:latest
    restart: always
    ports:
      - 10083:3000
    networks:
      - dpnet
 widget-ws:
    container_name: widget-ws
    image: registry.gitlab.com/myproject/widget-ws:latest
    restart: always
    ports:
      - 10084:3001
    networks:
      - dpnet
networks:
  dpnet:
    driver: bridge

I use container_name insteed url http://widget-ws:10084 but got error connect ECONNREFUSED 172.21.0.2:10084


Solution

  • Use the url: http://widget-ws:3001

    Containers talk to each other on internal ports not the ones mapped to your host.

    It is not necessary to create the network.