在不同的环境下运行docker-build不一致

本地一切运行平稳完美:

  • Mac OS 10.11.6
  • Docker 17.03.1-ce-mac12

在CircleCI上,远程的情况有所不同:

  • Ubuntu 14.04
  • Docker版本1.9.1-circleci-cp-workaround
  • 我正在使用CircleCI 1.0,我简单地尝试过使用CircleCI 2.0

我的Dockerfile看起来非常相似:

FROM pensiero/apache-php # Mostly Ubuntu 16.04 install with some php and node / npm # RUN apt-get install a few packages COPY . /var/www WORKDIR /var/www RUN ["npm","install"] # or RUN npm install 

然后,混乱被释放,所有的幸福消失:

 npm WARN deprecated bower@1.8.0: ..psst! While Bower is maintained, we recommend Yarn and Webpack for *new* front-end projects! Yarn's advantage is security and reliability, and Webpack's is support for both CommonJS and AMD projects. Currently there's no migration path but we hope you'll help us figure out one. npm WARN deprecated babel@6.23.0: In 6.x, the babel package has been deprecated in favor of babel-cli. Check https://opencollective.com/babel to support the Babel maintainers # This one is only there from time to time npm ERR! Cannot read property 'write' of null npm WARN optional SKIPPING OPTIONAL DEPENDENCY: lodash@4.17.4 (node_modules/babel-traverse/node_modules/lodash): npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, chown '/var/www/node_modules/.staging/lodash-23934876/camelCase.js' npm WARN optional SKIPPING OPTIONAL DEPENDENCY: base62@1.2.0 (node_modules/base62): npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, chown '/var/www/node_modules/.staging/base62-c9d76f67/.travis.yml' ... bunch of similar lines npm ERR! path /var/www/node_modules/.staging/react-dom-414d50ba npm ERR! code EINVAL npm ERR! errno -22 npm ERR! syscall chown npm ERR! EINVAL: invalid argument, chown '/var/www/node_modules/.staging/react-dom-414d50ba' npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2017-06-13T13_25_03_833Z-debug.log 

显示问题的环境的docker信息:

 Containers: 0 Images: 0 Server Version: 1.9.1-circleci-cp-workaround Storage Driver: btrfs Execution Driver: lxc-1.0.9 Logging Driver: json-file Kernel Version: 3.13.0-119-generic Operating System: Ubuntu 14.04.4 LTS (containerized) CPUs: 2 Total Memory: 58.97 GiB Name: box731 ID: 7CUB:SOW3:C3EG:LNFC:JWZB:O73I:PFPI:4XLM:NXDI:V44F:XEFB:IGTV Debug mode (server): true File Descriptors: 12 Goroutines: 17 System Time: 2017-06-13T15:32:31.903542525Z EventsListeners: 0 Init SHA1: Init Path: /usr/bin/docker Docker Root Dir: /var/lib/docker WARNING: No swap limit support WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled 

随机出现的错误导致我发出https://github.com/moby/moby/issues/783 ,它引用了一个关于AUFS的错误,应该修复这个错误。 而且似乎我没有使用AUFS …所以这也许是无关紧要的。

如果我删除产生错误的行,我可以稍后使用CircleCI文档中build议的docker docker exec补丁程序运行npm install

 sudo lxc-attach -n "$(docker inspect --format "{{.Id}}" test)" -- bash -c "cd /var/www; npm install" 

它工作正常,但我想得到一个构build神器释放…和exerything像这样跑并没有坚持。

提前致谢。

这听起来像是已经报告在https://discuss.circleci.com/t/npm-install-error-that-isnt-reproducing-in-a-local-docker-container/13085相同的事情。 可能值得跟随这个线程知道什么时候修复。 这可能与CircleCI有关。

(在CircleCI上经历过这个问题)

这是我的解决办法; 在任何其他COPYRUN命令之前编辑并将这些行添加到您的Dockerfile:

 ... RUN install -d -o node -g node /myapp WORKDIR /myapp USER node ... (COPY, RUN, etc) 

我的容器是基于node:8.1.4图像。 从node:6.11.0升级时触发此问题。 如果您使用不同的图像,则容器中可用的用户可能不同。 在这种情况下,你可以创build一个新的用户或者找出用户已经存在的东西,比如ubuntu或者其他的。

有一些非常有创意的解决方法,但这是一个非常简单的权限问题。 没有深入挖掘它比我所需要的,但添加USER到Dockerfile已经在我的待办事项列表,所以不是所有都丢失。 看起来像一个大问题,希望这可以节省别人一些麻烦。