Reputation: 1726
I have a Dockerfile in my rails project, that ends with:
CMD ["bundle", "exec", "unicorn", "-D", "-c /usr/src/app/config/unicorn.rb"]
When I run a container I get:
/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
Which I don't understand, because when I change the CMD to CMD ["cat", "config/unicorn.rb"]
, docker run <image>
correctly outputs the file.
After some try and error I found out that:
CMD bundle exec unicorn -D -c /usr/src/app/config/unicorn.rb
works fine.
After consulting the Docker docs I saw that when using the format CMD ["executable","param1","param2"]
it is required to give the full path to the executable. This I did not do in my initial attempt.
I went on an changed the CMD to:
CMD ["/usr/local/bin/bundle", "exec", "unicorn", "-D", "-c /usr/src/app/config/unicorn.rb"]
which worked!
What's confusing me, is that in the initial attempt bundle exec unicorn
still ran, but just did not find the config file.
Can anybody exaplain this behaviour? Why did my intial attemp run, but not find the file and the other two versions work fine?
For anybody looking to reproduce this. Here is the Dockerfile:
FROM benjaminbauer/ruby:latest
ONBUILD EXPOSE 8080
CMD ["/usr/local/bin/bundle", "exec", "unicorn", "-D", "-c /usr/src/app/config/unicorn.rb"]
The benjaminbauer/ruby
is just a fork of the official ruby image with cached bundle install. Use the cache_bundle_install
branch if you want to build it.
Upvotes: 1
Views: 1126