1
votes

I lifted docker file from

https://medium.com/@andyccs/webpack-and-docker-for-development-and-deployment-ae0e73243db4

# Dockerfile (tag: v3)
FROM node:4.7

RUN npm install webpack -g

WORKDIR /webCode/
COPY package.json .
RUN npm config set registry http://registry.npmjs.org/ && npm install

WORKDIR /usr/src/app
COPY . /usr/src/app/
RUN cp -a /webCode/node_modules /usr/src/app/
RUN webpack

CMD npm run start  
EXPOSE 8080

I have "start": "webpack-dev-server --host 0.0.0.0" in my package.json file.

In the terminal it runs okay. However, when I use browser to connect to the localhost:8080 it shows refused to connect error.

Here is the what I got from docker run -t container

npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info prestart [email protected]
npm info start [email protected]

> [email protected] start /usr/src/app
> webpack-dev-server --host 0.0.0.0

Project is running at http://0.0.0.0:8080/
webpack output is served from /
Hash: ecb5b52795042a7c522b
Version: webpack 2.7.0
Time: 10569ms
    Asset     Size  Chunks                    Chunk Names
bundle.js  5.12 MB       0  [emitted]  [big]  main
chunk    {0} bundle.js (main) 1.74 MB [entry] [rendered]
    [1] ./~/react/react.js 56 bytes {0} [built]
   [19] ./~/react-dom/index.js 59 bytes {0} [built]
   [49] ./~/react-redux/es/index.js 230 bytes {0} [built]
  [102] ./~/redux/es/index.js 1.08 kB {0} [built]
  [252] (webpack)-dev-server/client/overlay.js 3.73 kB {0} [built]
  [253] (webpack)-dev-server/client/socket.js 897 bytes {0} [built]
  [269] (webpack)-dev-server/~/strip-ansi/index.js 161 bytes {0} [built]
  [270] (webpack)/hot/emitter.js 77 bytes {0} [built]
  [271] (webpack)/~/node-libs-browser/~/url/url.js 23.3 kB {0} [built]
  [272] ./src/index.js 717 bytes {0} [built]
  [273] (webpack)-dev-server/client?http://0.0.0.0:8080 5.68 kB {0} [built]
  [274] (webpack)-dev-server/client?http://0.0.0.0:8080/ 5.68 kB {0} [built]
  [276] ./src/components/App.js 1.25 kB {0} [built]
  [285] ./src/reducer/index.js 927 bytes {0} [built]
  [621] multi (webpack)-dev-server/client?http://0.0.0.0:8080 webpack-dev-server/client?http://0.0.0.0:8080/ ./src 52 bytes {0} [built]
     + 607 hidden modules
webpack: Compiled successfully.

In terminal when I run webpack-dev-server --host 0.0.0.0 it works fine. I wonder why couldn't I view the homepage by run docker command.

1

1 Answers

1
votes

You forgot to map your port? Try

docker run -p 8080:8080 your_image