Search code examples
dockernx.dev

Unable to connect to nx app running inside docker container


I am unable to open the app from browser. Running the following command inside docker:

nx serve --port 80

Docker is started with following command:

docker run -p 80:80 -d <my_nx_app_image>

I am able to get the index.html from terminal (inside running docker container)

wget http://localhost:80


Solution

  • Steps:

    • Open project.json file of your nx app.
    • Find the key "serve" and search for parameter "configuration" under it.
    • Add a param with name "hostname" with value 0.0.0.0

    Example:

    "production": {
          "buildTarget": "<your_nx_app>:build:production",
          "dev": false,
          "hostname": "0.0.0.0"
        }
    

    Note: By default nx daemon does not allow remote connections on ports below 1024 by default.