0

我正在使用 chef-solo 在 docker 中运行社区 gerrit 食谱。

如果我在 Dockerfile 中运行说明书作为构建步骤,它会引发错误(检查日志)。但是,如果我运行图像并进入容器并运行相同的命令,它就可以正常工作。

知道发生了什么吗?它抱怨 sudo,但仍在继续并创建符号链接。'target_mode = nil' 应该不是问题,因为当我在容器内运行命令时它也会抱怨同样的事情,但工作正常。它最终抱怨 init.d 脚本没有意义。

chef-solo 作为构建步骤:

RUN chef-solo --log_level debug -c /resources/solo.rb -j /resources/node.json

日志:

[ :08+01:00] INFO: Processing ruby_block[gerrit-init] action run (gerrit::default line 225)
sudo: sorry, you must have a tty to run sudo
[ :08+01:00] INFO: /opt/gerrit/war/gerrit-2.7.war exist....initailizing gerrit
[ :08+01:00] INFO: ruby_block[gerrit-init] called
[ :08+01:00] INFO: Processing link[/etc/init.d/gerrit] action create (gerrit::default line 240)
[ :08+01:00] DEBUG: link[/etc/init.d/gerrit] created symbolic link from /etc/init.d/gerrit -> /opt/gerrit/install/bin/gerrit.sh
[ :08+01:00] INFO: link[/etc/init.d/gerrit] created
[ :08+01:00] DEBUG: found target_mode == nil, so no mode was specified on resource, not managing mode
[ :08+01:00] DEBUG: found target_uid == nil, so no owner was specified on resource, not managing owner
[ :08+01:00] DEBUG: found target_gid == nil, so no group was specified on resource, not managing group
[ :08+01:00] INFO: Processing link[/etc/rc3.d/S90gerrit] action create (gerrit::default line 244)
[ :08+01:00] DEBUG: link[/etc/rc3.d/S90gerrit] created symbolic link from /etc/rc3.d/S90gerrit -> ../init.d/gerrit
[ :08+01:00] INFO: link[/etc/rc3.d/S90gerrit] created
[ :08+01:00] DEBUG: found target_mode == nil, so no mode was specified on resource, not managing mode
[ :08+01:00] DEBUG: found target_uid == nil, so no owner was specified on resource, not managing owner
[ :08+01:00] DEBUG: found target_gid == nil, so no group was specified on resource, not managing group
[ :08+01:00] INFO: Processing service[gerrit] action enable (gerrit::default line 248)
[ :08+01:00] DEBUG: service[gerrit] supports status, running

================================================================================
Error executing action `enable` on resource 'service[gerrit]'
================================================================================

Chef::Exceptions::Service
-------------------------
service[gerrit]: unable to locate the init.d script!

Resource Declaration:
---------------------
# In /var/chef/cookbooks/gerrit/recipes/default.rb

248: service 'gerrit' do
249:   supports :status => false, :restart => true, :reload => true
250:   action [ :enable, :start ]
251: end
252:

Compiled Resource:
------------------
# Declared in /var/chef/cookbooks/gerrit/recipes/default.rb:248:in `from_file'

service("gerrit") do
  action [:enable, :start]
  supports {:status=>true, :restart=>true, :reload=>true}
  retries 0
  retry_delay 2
  guard_interpreter :default
  service_name "gerrit"
  pattern "gerrit"
  cookbook_name :gerrit
  recipe_name "default"
end
4

2 回答 2

0

容器不是虚拟机,这意味着它们运行单个进程并且没有运行进程管理器。这解释了为什么 chef-solo 在创建服务资源时会遇到问题。

我建议阅读 Chef 为容器设计的一些新兴支持:

我并不假装它在第一次阅读时很有意义。我还不能相信 chef 是构建容器的最佳方式。

于 2014-09-27T08:57:09.893 回答
0

实际的错误是sudo: sorry, you must have a tty to run sudo,由于安全原因未分配 linux 终端,更多信息在此链接中。

默认情况下,Docker 以 root 身份运行,无需执行 sudo。我正在运行的食谱创建了“gerrit”用户,这导致我执行 sudo。我删除了用户并以 root 身份运行所有内容。解决了!

于 2015-01-13T18:16:13.267 回答