Nx: Web-Dev-Server is incompatible with Docker containers

Created on 17 Sep 2019  路  5Comments  路  Source: nrwl/nx

Expected Behavior

Should be able to serve apps inside Docker containers.

Current Behavior

Container mounts correctly and the server starts but cannot be connected to on the host machine.

Steps to Reproduce

  1. Create a new workspace
  2. Generate a simple react app called myTodoApp
  3. docker run -it -p 4200:4200 -v $PWD:/home/node node:12 yarn --cwd /home/node nx serve myTodoApp --host=0.0.0.0

Context

  • Nx: 8.5.0
  • Docker for Mac: Docker version 19.03.2, build 6a30dfc

Other

The issue is caused by --host=0.0.0.0 being ignored by dev-server.impl.ts at line 79

If I remove the check allowing 0.0.0.0 through, I can then connect to the server. I use docker to run related Nx apps together during development.

more info needed bug

Most helpful comment

Based on the code it looks like the only thing it can affect is live reloading.

Folks, are you interesting in seeing if it affects live reloading? If yes, we can leave the check as is and maybe another flag. If not, we can just remove it.

All 5 comments

Sorry, my knowledge of docker is limited.

Why is passing the host necessary? Also, it replaces the value with localhost.. Is that invalid for some reason?

@FrozenPandaz when inside a docker container, localhost refers to the docker container and not the host, so effectively it is only allowing connections from within the container

Yes @FrozenPandaz, @xtiancapil is right. Although for other projects, here is a bit more info; brief explanations of basically the same issue with inside / outside container host / port binding:

SO: docker-empty-response-from-server
SO: err-empty-response-from-docker-container
SO: running-rust-on-docker-empty-reply-from-server

@ckokotas's observation that line 79 of dev-server.impl.ts should probably not replace a passed in param _0.0.0.0_ with _localhost_ seems like it would fix the problem, although I don't know what other implications that would have.

Based on the code it looks like the only thing it can affect is live reloading.

Folks, are you interesting in seeing if it affects live reloading? If yes, we can leave the check as is and maybe another flag. If not, we can just remove it.

Fixed by #2129 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZempTime picture ZempTime  路  3Comments

joelmuskwe picture joelmuskwe  路  3Comments

markphip picture markphip  路  3Comments

about-code picture about-code  路  3Comments

dereklin picture dereklin  路  3Comments