skip to Main Content

I am facing a communication issue between two services within the same Docker container using Docker Compose. My docker-compose.yml file:

services:
  web_frontend:
    container_name: web_frontend
    hostname: web_frontend
    build:
      context: ./vero_webapp
      dockerfile: Dockerfile_nextjs
    ports:
      - "3000:3000"
    depends_on:
      - web_backend

  web_backend:
    container_name: web_backend
    hostname: web_backend
    build:
      context: ./apiveroprodutos
      dockerfile: Dockerfile_django
    ports:
      - "8000:8000"

The issue arises when I attempt to access the URL http://web_backend:8000; I receive an ENOTFOUND error (getaddrinfo). This call occurs during the docker compose up right after the backend container is started, and the front-end one is finishing. It attempts to make the call and breaks with the error I pointed out, without even completing the build. From my understanding, Docker Compose should establish a link between the services based on the hostname, allowing seamless communication. Issue sample:

1.071    Creating an optimized production build ...
39.62  ✓ Compiled successfully
39.62    Linting and checking validity of types ...
39.75    Collecting page data ...
41.02 http://web_backend:8000/bling/api/product/searchAndPagination?
41.06 Products Api Error: TypeError: fetch failed
41.06     at Object.fetch (node:internal/deps/undici/undici:11730:11)
41.06     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
41.06   cause: Error: getaddrinfo ENOTFOUND web_backend
41.06       at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:107:26)
41.06       at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:128:17) {
41.06     errno: -3008,
41.06     code: 'ENOTFOUND',
41.06     syscall: 'getaddrinfo',
41.06     hostname: 'web_backend'
41.06   }
41.06 }

I’ve checked the configuration, and it seems correct. However, I’m still encountering the communication problem. Can someone please help me identify what might be causing this issue or suggest a solution? Am I missing any configurations or steps to enable proper communication between the services?

2

Answers


  1. Chosen as BEST ANSWER

    I managed to solve the problem, thanks to all the friends who were here to help! The issue was in the most ridiculous thing of all – the use of an underscore in the name. Apologies for the naivety.


  2. In order for your services to communicate together, they should be in the same network. Create a network and add both your services to this network and it should work

    Code :

    services:
      web_frontend:
        container_name: web_frontend
        hostname: web_frontend
        build:
          context: ./vero_webapp
          dockerfile: Dockerfile_nextjs
        ports:
          - "3000:3000"
        depends_on:
          - web_backend
        networks:
          - my_network
    
      web_backend:
        container_name: web_backend
        hostname: web_backend
        build:
          context: ./apiveroprodutos
          dockerfile: Dockerfile_django
        ports:
          - "8000:8000"
        networks:
          - my_network
    
    networks:
        my_network:
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search