docker如何解释CMD?

时间:2014-07-18 15:39:34

标签: ruby-on-rails docker unicorn

初始Attemtp

我的rails项目中有一个Dockerfile,结尾为:

CMD ["bundle", "exec", "unicorn", "-D", "-c /usr/src/app/config/unicorn.rb"]

当我运行一个容器时,我得到:

/usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:75:in `read': No such file or directory @ rb_sysopen -  /usr/src/app/config/unicorn.rb (Errno::ENOENT)
    from /usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:75:in `reload'
    from /usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/lib/unicorn/configurator.rb:68:in `initialize'
    from /usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:100:in `new'
    from /usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:100:in `initialize'
    from /usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `new'
    from /usr/local/lib/ruby/gems/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
    from /usr/local/bin/unicorn:23:in `load'
    from /usr/local/bin/unicorn:23:in `<main>'
master failed to start, check stderr log for details

我不明白,因为当我将CMD更改为CMD ["cat", "config/unicorn.rb"]时,docker run <image> 会正确输出文件

CMD作为shell

经过一番尝试和错误后,我发现:

CMD bundle exec unicorn -D -c /usr/src/app/config/unicorn.rb

正常运作

正确尝试

在咨询Docker docs后,我发现在使用格式CMD ["executable","param1","param2"]时,需要为可执行文件提供完整路径。我在最初的尝试中没有这样做。

我继续将CMD更改为:

CMD ["/usr/local/bin/bundle", "exec", "unicorn", "-D", "-c /usr/src/app/config/unicorn.rb"]

工作

问题

令我困惑的是,在初始尝试中bundle exec unicorn仍在运行,但却找不到配置文件。

有人可以冒充这种行为吗?为什么我的初始尝试运行,但找不到文件,其他两个版本正常运行?

修改

对于任何想要重现这一点的人。这是Dockerfile:

FROM benjaminbauer/ruby:latest

ONBUILD EXPOSE 8080
CMD ["/usr/local/bin/bundle", "exec", "unicorn", "-D", "-c /usr/src/app/config/unicorn.rb"]

benjaminbauer/ruby只是official ruby image cached bundle install的一个分支。如果您想构建它,请使用cache_bundle_install branch

0 个答案:

没有答案