skip to Main Content

I use the docker desktop app on Windows.
Inside a Ubuntu WSL2 I have a docker container with a meteor / nodejs server running.
Started via docker-compose from inside the WSL.

docker-compose.yaml
  ...
  environment:
    - ROOT_URL=http://localhost:8080
    - PORT=8080
  ports:
    - "8080:8080"

Now the app inside the docker container must access an HTTP endpoint of itself like http://127.0.0.1:8080/api

When I call the this endpoint from outside the docker, I get the correct result.
When I connect into the docker container with a terminal and curl the endpoint, I get the correct result.
But, when the running app / service running inside the container tries to call itself by the same endpoint with the same URL, I get a ECONNREFUSED - CONNECTION REFUSED error.

What could be the problem of this? Maybe a WSL2 security problem?

2

Answers


  1. I can’t say anything for sure without looking at the actual code or seeing the full error message, but try to replace your

    - ROOT_URL=http://localhost:8080
    

    with

    - ROOT_URL=http://127.0.0.1:8080
    

    And if you have any other places with localhost url, replace them as well.

    Login or Signup to reply.
  2. I also can’t say anything certainly without looking at the code or error, but have you tried replacing the localhost with the name of the container within the compose file?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search