2014-09-27 113 views
0

我使用厨师独奏在docker上运行社区gerrit食谱。如何在码头集装箱内运行gerrit cookbook?

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

任何想法是怎么回事?它抱怨sudo,但继续并创造象征性的联系。 'target_mode = nil'应该不是问题,因为它在容器中运行命令时也抱怨同样的事情,但工作正常。它最终抱怨init.d脚本没有意义。

厨师独奏作为构建步骤:

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 

回答

0

实际错误是sudo: sorry, you must have a tty to run sudo,由于安全原因,linux终端未分配,更多信息请登录this link here

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

0

容器不是虚拟机,这意味着他们跑单的过程,而不是有过程管理运行。该解释了为什么厨师-solo会在创建服务资源时遇到问题。

我建议阅读一些新兴支持,厨师正在设计的容器:

我不会假装它使大量的意义在第一读。我还没有相信厨师是建立集装箱的最佳方式。

+0

有趣。你是说在构建Dockerfile的时候,它是在单一进程上运行的,当容器启动时它可以有多个进程?我当然不会使用像supervisord这样的花式东西。当我在正在运行的容器中运行chef-solo命令时,我没有遇到任何问题。 – 2014-09-27 09:21:27

+0

@SushanGhimire不完全。我在说,你不能认为supervisord是安装并运行的,用你的厨师独奏来解释你的错误开始一个不存在的服务。没有任何东西可以阻止你像supervisord或runit那样明确的进程管理器,但它需要更多的docker配置。从我读到的新的“厨师初始化”过程旨在了解这个受限制的环境,以便厨师资源按照我们预期的那样运行。 – 2014-09-27 19:56:25