Next.XP over Docker ECONNREFUSED

Enonic version: 7.13.1
OS: Ubuntu 22.04.1 LTS

Hi!!!

I am trying to migrate my Next.XP app to run inside Docker containers. The application was already working when running both Enonic and Node servers in my host machine, but when it comes to two separated containers, I receive the following error:

http://127.0.0.1:8080/site/myproject/master TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error: connect ECONNREFUSED 127.0.0.1:8080
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 8080
  }
}

Both containers are using the same docker networks and from a container I am able to ping other.

Is there any configuration in the Next application to allow the connection from another host?

Thanks!

Hi, stanzani

I’m assuming that the error that you’ve provided is from an attempt were your Node.js container is attempting to connect to your Enonic XP container? In that case, the address 127.0.0.1:8080 would not work across containers.

Are you familiar with how networking with standalone Docker containers works?

To debug the docker network, do a docker network ls and identify the common bridge network for both your containers (hopefully you’ve made your own and not just used the default?)
Then do a docker network inspect myBridgeNetworkName to verify that both containers are on that network, and check their IP addresses which typically is something like 172.17.0.2

If you’re following best practice and using your own bridge network instead of just the default bridge network, you can reach containers by name and not just IP address, for example if you have named your docker containers exp and node then you can reach Enonic XP from Node.js using http://exp:8080 and oppositely reach Node.js from Enonic XP using http://node:3000

In that case, you can update your virtualhost mappings so that Enonic XP responds to requests where host equals “exp” or whatever your Enonic XP docker container name is, and not just localhost which is what Enonic XP responds to by default even when virtualhost mappings are disabled.

Thank you for your help, @bhj

It worked after using the “XpContainerName:8080” instead of “127.0.0.1:8080” inside the Next application’s .env file and replacing the “localhost:3000” with “NextContainerName:3000” in the Next.XP adapter config.

I will change the .env.development to contain this specific configuration.

Just for information:

To debug the docker network, do a docker network ls and identify the common bridge network for both your containers (hopefully you’ve made your own and not just used the default?)
Then do a docker network inspect myBridgeNetworkName to verify that both containers are on that network, and check their IP addresses which typically is something like 172.17.0.2

Both containers were already in the same “MyNetwork”, and I could send a “ping” from one container to another.

Thank you for your help!!!