0

I'm attempting to expose a react application to the Docker container it currently sits inside.

My Dockerfile successfully builds my image and runs my application on the configured port (8080). I then try to bind port 8080 of the container to port 8080 of the host. However, when I visit the host machine at port 8080 my application is not here.

docker run -d -p 8080:8080 --name react-deployment-container react-deployment:dev

I have an existing node application already exposed on the same host machine running on a different port (3000), so I am confident it is not an issue binding a port when running the Docker container.

I think the issue might be the way I am attempting to expose the application in my Webpack configuration. Webpack builds perfectly but doesn't appear to available to the Docker container.

webpack.config.js

devServer: {
    contentBase: path.join(__dirname, "dist"),
    compress: true,
    host: '0.0.0.0',
    port: 8080
  }

package.json

"scripts": {
    "start": "webpack-dev-server --host 0.0.0.0"
  },

I have tinkered with the configuration recommended in the two questions below with no luck.

How to make the webpack dev server run on port 80 and on 0.0.0.0 to make it publicly accessible?

https://github.com/webpack/webpack-dev-server/issues/547

The repo for this project is here

Eoin Traynor
  • 600
  • 4
  • 8
  • Anything useful in "docker logs "? Is the container running at all? Try "docker ps". – JeffRSon Sep 06 '17 at 16:26
  • is your container up, check with "docker ps -a", if the container react-deployment-container is up then check the logs of the container by id with "docker logs " – Jinna Balu Sep 06 '17 at 18:29
  • Can you go inside the container and use `curl localhost:8080` – Tarun Lalwani Sep 07 '17 at 05:47
  • @Tarun Lalwani Yes. It prints the contents of the index file. So that makes me assume the container is running fine. Do I need to expose the application publicly i.e. not just localhost? – Eoin Traynor Sep 07 '17 at 11:01
  • @JeffRSon Yes, the container is running and on port `8080/tcp -> 0.0.0.0:8080`. – Eoin Traynor Sep 07 '17 at 11:09
  • Which OS are you using? And are you running docker inside a VM? – Tarun Lalwani Sep 07 '17 at 11:12
  • What about curl localhost:8080 from outside the docker container? Or the source view from browser? What does it mean "it's not there"? – JeffRSon Sep 08 '17 at 06:04
  • @JeffRSon A curl request to localhost:8080 from the host machine (not inside the container) returns the contents of the index page. What I mean is that the application is not available on this port from the browser. I am only seeing an 'Invalid Host header' error message. – Eoin Traynor Sep 08 '17 at 11:13
  • @JeffRSon @Tarun Lalwani @Jinna Balu Once I specified the public IP of my server it worked fine `--public 165.227.184.93:8080`. – Eoin Traynor Sep 11 '17 at 10:22

0 Answers0