docker工作人员如何解释CMD?

初始的尝试

我在我的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"]CMD ["cat", "config/unicorn.rb"] docker run <image> 正确输出文件

CMD作为一个shell

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

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

工作正常

正确的尝试

在查阅了Docker文档之后,我发现当使用格式CMD ["executable","param1","param2"]需要给出可执行文件的完整path 。 这在我最初的尝试中并没有这样做。

我继续把CMD改成:

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

哪个工作

有什么让我困惑的是,在最初的尝试bundle exec unicorn仍然运行,但只是没有findconfiguration文件。

任何人都可以离开这种行为吗? 为什么我的初始尝试运行, 但没有find该文件 ,其他两个版本工作正常?

编辑

任何人都希望重现这一点。 这是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只是官方ruby镜像的一个分支,使用caching的bundle安装 。 如果要构build它,请使用cache_bundle_install 分支 。