1

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?

3
  • 1
    Add your Dockerfile to your question. Commented May 19, 2017 at 18:11
  • In your Dockerfile are you copying the file into the image? That two line Dockerfile doesn't show you doing it. Commented May 19, 2017 at 21:20
  • The -onbuild image variant does that. It actually copies it to /usr/src/app: github.com/docker-library/ruby/blob/master/2.1/onbuild/… Commented May 19, 2017 at 21:27

1 Answer 1

1

Are you sure you're running the script correctly? Shouldn't be

CMD ["ruby", "./test.rb"]

?

I mean, I can suppose the script has executable permission but it's not a shell script.

Sign up to request clarification or add additional context in comments.

4 Comments

While I agree with this answer, I think there are actually two issues going on. The second is that they are testing for the file in a new container. The file wouldn't exist in their test anyways. You should point that out in your answer.
Do you mean we don't know how the script is in the container? I presume volumes
Why not? We don't know. User didn't put a feedback
The command they used to test didn't mount any volume. I'm assuming they are copying the file into the image during build. Regardless if they do or mount it at runtime, the example still wouldn't work because it doesn't mount a volume.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.