#NestJS/Docker in dev mode binding to 127.0.0.1 instead of 0.0.0.0 for Docker Compose

8 messages · Page 1 of 1 (latest)

minor notch
#

I am trying to define current stack in a docker-compose.yml to share with other developers in the project, so have the NestJS container started with:

npm run start:dev

which is defined in the package.json as:

NODE_ENV=development nest start --watch -- --inspect --max_old_space_size=1024

and in main.ts there is:

  if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'prod') {
    await app.listen(3001, '0.0.0.0');
    console.log(`Application is in PRODUCTION mode running on: ${await app.getUrl()}`);
  } else {
    await app.listen(3001, '0.0.0.0');
    console.log(`Application is in DEV mode running on: ${await app.getUrl()}`);
  }

However, when docker compose up runs, the container outputs:

api-server-api-server-1  | Application is in DEV mode running on: http://127.0.0.1:3001

This of course results in no ability to access the service from the host at the ip/port since it's not even binding (and proven by looking at the netstat -an | grep 3001 from the host).

How can I expose this service appropriately?

austere forge
#

Are you aware that you need to expose ports in the docker-compose file?

- ports:
  # host_port:container_port
  - '3001:3001'
minor notch
#

But it still doesn't seem to work.

#

That said, it could also be related to having the containers talking on a private network.

#

I guess I need to add a bridged network to this specific container as well...

minor notch
#

Something has changed in newer NestJS though. I just upgraded production (which runs in containers) and am seeing the 127.0.0.1 instead of 0.0.0.0.

#

It use to show 0.0.0.0.