运行runit cookbook时,packer docker build退出代码137

我正在尝试使用Packer来构build我正在使用的webapp的docker镜像。 每当我运行runit packer build ,当它到达它运行runit配方的步骤,我会得到Build 'docker' errored: Error executing Chef: Non-zero exit status: 137

我看了看137,发现这是通常与kill -9关联的退出码。 在大多数情况下,这意味着系统在内存上运行严重不足,系统正在尝试进行补偿。

我试图find最小的可能的复制,我想出了这个打包机configuration:

 { "builders":[{ "type": "docker", "pull": false, "image": "silkstart/basic_server", "export_path": "image.tar", "run_command":[ "-d", "-i", "-t", "--memory-reservation", "1G", "{{.Image}}", "/bin/bash" ] }], "provisioners":[ { "type": "chef-solo", "cookbook_paths": ["cookbooks", "vendor/cookbooks"], "data_bags_path": "data_bags", "roles_path": "roles", "environments_path": "environments", "run_list": [ "recipe[runit]" ] } ], "post-processors": [ { "type": "docker-import", "repository": "silkstart/docker_test", "tag": "0.1" } ] } 

当我运行packer build这个configuration时,这是我的输出:

 TMPDIR=/opt/shared packer build packer_files/docker_test.json docker output will be in this color. ==> docker: Creating a temporary directory for sharing data... ==> docker: Starting docker container... docker: Run command: docker run -v /opt/shared/packer-docker484290992:/packer-files -d -i -t --memory-reservation 1G silkstart/basic_server /bin/bash docker: Container ID: 1f87b0cf1fe71f07b580ae6b18415a79c23a1a32a40f5f0366be90f160977a50 ==> docker: Provisioning with chef-solo docker: Installing Chef... docker: % Total % Received % Xferd Average Speed Time Time Time Current docker: Dload Upload Total Spent Left Speed docker: 100 20022 100 20022 0 0 45092 0 --:--:-- --:--:-- --:--:-- 45196 docker: Getting information for chef stable for ubuntu... docker: downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=&p=ubuntu&pv=14.04&m=x86_64 docker: to file /tmp/install.sh.23/metadata.txt docker: trying curl... docker: url https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.6.0-1_amd64.deb docker: md5 5cfc19d5a036b3f7860716bc9795a85e docker: sha256 e0b42748daf55b5dab815a8ace1de06385db98e29a27ca916cb44f375ef65453 docker: version 12.6.0downloaded metadata file looks valid... docker: downloading https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/14.04/x86_64/chef_12.6.0-1_amd64.deb docker: to file /tmp/install.sh.23/chef_12.6.0-1_amd64.deb docker: trying curl... docker: Comparing checksum with sha256sum... docker: docker: WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING docker: docker: You are installing an omnibus package without a version pin. If you are installing docker: on production servers via an automated process this is DANGEROUS and you will docker: be upgraded without warning on new releases, even to new major releases. docker: Letting the version float is only appropriate in desktop, test, development or docker: CI/CD environments. docker: docker: WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING docker: docker: Installing chef docker: installing with dpkg... docker: Selecting previously unselected package chef. docker: (Reading database ... 17195 files and directories currently installed.) docker: Preparing to unpack .../chef_12.6.0-1_amd64.deb ... docker: Unpacking chef (12.6.0-1) ... docker: Setting up chef (12.6.0-1) ... docker: Thank you for installing Chef! docker: Creating directory: /tmp/packer-chef-solo docker: Creating directory: /tmp/packer-chef-solo/cookbooks-0 docker: Creating directory: /tmp/packer-chef-solo/cookbooks-1 docker: Creating directory: /tmp/packer-chef-solo/roles docker: Creating directory: /tmp/packer-chef-solo/data_bags docker: Creating directory: /tmp/packer-chef-solo/environments docker: Creating configuration file 'solo.rb' docker: Creating JSON attribute file docker: Executing Chef: sudo chef-solo --no-color -c /tmp/packer-chef-solo/solo.rb -j /tmp/packer-chef-solo/node.json docker: [2016-01-29T06:42:48+00:00] INFO: Forking chef instance to converge... docker: [2016-01-29T06:42:48+00:00] INFO: *** Chef 12.6.0 *** docker: [2016-01-29T06:42:48+00:00] INFO: Chef-client pid: 207 docker: [2016-01-29T06:42:50+00:00] INFO: Setting the run_list to ["recipe[runit]"] from CLI options docker: [2016-01-29T06:42:50+00:00] INFO: Run List is [recipe[runit]] docker: [2016-01-29T06:42:50+00:00] INFO: Run List expands to [runit] docker: [2016-01-29T06:42:50+00:00] INFO: Starting Chef Run for 1f87b0cf1fe7 docker: [2016-01-29T06:42:50+00:00] INFO: Running start handlers docker: [2016-01-29T06:42:50+00:00] INFO: Start handlers complete. docker: [2016-01-29T06:42:52+00:00] INFO: Processing service[runit] action nothing (runit::default line 20) docker: [2016-01-29T06:42:52+00:00] INFO: Processing execute[start-runsvdir] action nothing (runit::default line 24) docker: [2016-01-29T06:42:52+00:00] INFO: Processing execute[runit-hup-init] action nothing (runit::default line 33) docker: [2016-01-29T06:42:52+00:00] INFO: Processing apt_package[runit] action install (runit::default line 64) docker: [2016-01-29T06:42:55+00:00] INFO: Processing cookbook_file[/var/chef/cache/preseed/runit/runit-2.1.1-6.2ubuntu3.seed] action create (dynamically defined) docker: [2016-01-29T06:42:55+00:00] INFO: cookbook_file[/var/chef/cache/preseed/runit/runit-2.1.1-6.2ubuntu3.seed] created file /var/chef/cache/preseed/runit/runit-2.1.1-6.2ubuntu3.seed docker: [2016-01-29T06:42:55+00:00] INFO: cookbook_file[/var/chef/cache/preseed/runit/runit-2.1.1-6.2ubuntu3.seed] updated file contents /var/chef/cache/preseed/runit/runit-2.1.1-6.2ubuntu3.seed docker: [2016-01-29T06:42:55+00:00] INFO: apt_package[runit] pre-seeding package installation instructions ==> docker: Killing the container: 1f87b0cf1fe71f07b580ae6b18415a79c23a1a32a40f5f0366be90f160977a50 Build 'docker' errored: Error executing Chef: Non-zero exit status: 137 

我不完全确定是什么导致代码137,任何帮助,将不胜感激。


更新1

我包含了Chef的完整debugging输出的要点。 这更为详细,主要是因为Ohai为获取信息所做的所有尝试。

https://gist.github.com/jrstarke/4c5f3b432aaee70c7f77

在这里没有任何引用似乎表明内存不足错误,至less在docker主机。

经过多less挖掘,我发现这个问题。 潜在的问题和解决scheme都在cloudfoundry-incubator / garden-linux的一个问题上find。

显然,作为安装过程的一部分, runit一个post init脚本执行kill -s HUP 1 。 为什么我不完全确定,但正如他们在那里指出的那样,在我的apt-get install runittrap HUP之前做一个trap '' HUP trap HUP完全解决了我的问题。

检查主机上的OOM日志。 您也可以使用execute_commandconfiguration值来将日志级别debugging。

这个答案似乎适用于我: https : //stackoverflow.com/a/42398166/2878244

我不得不通过转到Docker选项卡>首选项>高级来增加分配给docker的内存资源

Docker高级设置