docker-compose can't connect to adjacent service via service name
Your application is listening on loopback:
$ docker run --rm --net container:demo-dockercompose-network_frontend_1 nicolaka/netshoot ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:PortLISTEN 0 128 127.0.0.11:35233 *:*LISTEN 0 128 127.0.0.1:3000 *:*
From outside of the container, you cannot connect to ports that are only listening on loopback (127.0.0.1
). You need to reconfigure your application to listen on all interfaces (0.0.0.0
).
For your app, in the package.json, you can add (according to the nuxt faq):
"config": { "nuxt": { "host": "0.0.0.0", "port": "3000" } },
Then you should see:
$ docker run --rm --net container:demo-dockercompose-network_frontend_1 nicolaka/netshoot ss -lntState Recv-Q Send-Q Local Address:Port Peer Address:PortLISTEN 0 128 *:3000 *:*LISTEN 0 128 127.0.0.11:39195 *:*
And instead of an unreachable error, you'll now get a 500:
...frontend_1 | response: undefined, frontend_1 | statusCode: 500, frontend_1 | name: 'NuxtServerError' }...spec_1 | The response we received from your web server was:spec_1 | spec_1 | > 500: Server Error