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

时间:2017-06-13 15:42:27

标签: docker dockerfile circleci lxc

本地一切都运行顺畅和完美:

  • 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

显示问题的环境的泊坞窗信息:

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文档中建议的npm install补丁运行docker exec

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

它工作得很好,虽然我想获得一个用于发布的构建工件......并且exthingthing就像那样不会持久化。

提前致谢。

2 个答案:

答案 0 :(得分:1)

听起来好像已经在https://discuss.circleci.com/t/npm-install-error-that-isnt-reproducing-in-a-local-docker-container/13085报道了同样的事情。可能值得关注该线程以了解修复何时到位。它可能与CircleCI有关。

答案 1 :(得分:0)

(在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升级时会触发此问题。如果您使用不同的图像,则容器中可用的用户可能不同。在这种情况下,您可以创建新用户或确定用户已存在的内容,例如ubuntu或其他什么。

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