Docker中的webpack-dev-server

时间:2017-11-15 22:27:24

标签: docker webpack

我从

中解除了docker文件

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

我的package.json文件中有"start": "webpack-dev-server --host 0.0.0.0"

在终端中运行正常。但是,当我使用浏览器连接到localhost时:8080显示拒绝连接错误。

以下是我从docker run -t container

获得的内容
npm info it worked if it ends with ok
npm info using npm@2.15.11
npm info using node@v4.7.3
npm info prestart reactWeb@1.0.0
npm info start reactWeb@1.0.0

> reactWeb@1.0.0 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.

在运行webpack-dev-server --host 0.0.0.0的终端中,它工作正常。 我想知道为什么我不能通过运行docker命令查看主页。

1 个答案:

答案 0 :(得分:1)

您忘了映射您的端口?尝试

docker run -p 8080:8080 your_image