myo*_*yol 5 node.js npm docker
我在Dockerfile.
FROM node:9.11-alpine
COPY ./ /usr/src/app/
WORKDIR /usr/src/app/
RUN npm install && npm run build
ENTRYPOINT [ "npm", "run", "watch"]
Run Code Online (Sandbox Code Playgroud)
当我这样做时,docker build .成功完成构建的机会很小。在几分钟内,如果我定期运行相同的命令而不对我的Dockerfile或其他任何内容进行任何更改,则构建将会成功。大多数时候我都明白这一点;
...
npm WARN tar ENOENT: no such file or directory, open '/usr/src/app/node_modules/.staging/bluebird-5b126a50/js/browser/bluebird.js'
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://registry.npmjs.org/json-bigint/-/json-bigint-0.2.3.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-06-26T08_18_44_426Z-debug.log
Run Code Online (Sandbox Code Playgroud)
因为构建失败,我无法检查/root/.npm/_logs/2018-06-26T08_18_44_426Z-debug.log(至少据我所知)。该错误表明它是一个连接问题,但在线 npm 存储库是否有某种限制?或者 docker 的作用就像一个代理吗?
有没有一种方法可以将 npm 与 docker 一起使用来避免这个我不知道的错误?
编辑
npm install使用 shell 在容器内手动运行的详细日志
1420 verbose type system
1421 verbose stack FetchError: request to https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
1421 verbose stack at ClientRequest.req.on.err (/usr/local/lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/node-fetch-npm/src/index.js:68:14)
1421 verbose stack at ClientRequest.emit (events.js:180:13)
1421 verbose stack at TLSSocket.socketErrorListener (_http_client.js:395:9)
1421 verbose stack at TLSSocket.emit (events.js:180:13)
1421 verbose stack at emitErrorNT (internal/streams/destroy.js:64:8)
1421 verbose stack at process._tickCallback (internal/process/next_tick.js:178:19)
1422 verbose cwd /usr/src/app
1423 verbose Linux 4.14.48-2-MANJARO
1424 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
1425 verbose node v9.11.2
1426 verbose npm v5.6.0
1427 error code ENOTFOUND
1428 error errno ENOTFOUND
1429 error network request to https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443
1430 error network This is a problem related to network connectivity.
1430 error network In most cases you are behind a proxy or have bad network settings.
1430 error network
1430 error network If you are behind a proxy, please make sure that the
1430 error network 'proxy' config is set properly. See: 'npm help config'
1431 verbose exit [ 1, true ]
Run Code Online (Sandbox Code Playgroud)
为什么不将docker build无入口点和docker run有入口点分开呢?
尝试:
Dockerfile
FROM node:9.11-alpine
COPY ./ /usr/src/app/
WORKDIR /usr/src/app/
RUN npm install && npm run build
Run Code Online (Sandbox Code Playgroud)
之后,创建图像:
docker build -t your_image_name .
Run Code Online (Sandbox Code Playgroud)
使用网络模式=主机运行命令以避免一些与网络相关的问题:
docker run -d --net=host your_image_name npm run watch
Run Code Online (Sandbox Code Playgroud)
如果不起作用,您可以通过两种方式检查您的日志:
docker run -d -v /tmp/any_dir:/root/.npm/_logs/ ...可从主机获取。docker run -ti your_image_name sh| 归档时间: |
|
| 查看次数: |
2905 次 |
| 最近记录: |