Building a Docker image for a Ruby app using https://hub.docker.com/_/ruby/ I have a skeleton project with an empty Gemfile, Gemfile.lock and a 1 line Ruby script (test.rb) like this:
File.open("success.txt", 'w') { |file| file.write("Success!") }
Note the Dockerfile is:
FROM ruby:2.1-onbuild
CMD ["./test.rb"]
However, when I build and run it using:
docker build -t test-ruby-app .
docker run -it --name my-running-test-ruby-app test-ruby-app
I can see it's run and exited using docker ps. If attach to it using:
docker run --entrypoint=bash -it <image id>
I can see the Ruby script has not run (there's no success.txt file).
I can run it manually (after attaching to the image) using ./test.rb and it works as expected.
What could be the problem?
-onbuildimage variant does that. It actually copies it to/usr/src/app: github.com/docker-library/ruby/blob/master/2.1/onbuild/…