How does the onbuild directory for the official Rails docker image work?

I'm working on building a docker image for our team that uses a Ruby on Rails version that is too old to be supported by the official Docker image . In the process of backing up the official Rails image, I'm looking at the Dockerfile from the repository used to create the official image , and I don't understand how it all fits together. Specifically, how do I call the Dockerfile in the onbuild directory? There is no explicit call in the root of the Dockerfile.

I read the documentation for ONBUILD and couldn't find an answer.

+3


source to share


1 answer


Please note that as a basic Rails Dockerfile, and file Docker onbuild to start with one and the same image: ruby:2.1.5

. The image is onbuild

not invoked by the root Dockerfile — it is a separate image that is slightly more "ready to deploy" than the base Rails image.

For example, take a look at the basic Rails image . He got all the commands to set up the Rails application environment. However, it doesn't have anything to put your actual code into an image to run. You will need to have a Dockerfile that starts with this image, but then includes additional commands to inject your code.



Now check out the Rails onbuild image . You can put the Dockerfile in the root rails directory that just said FROM rails:onbuild

. When you create this image, it will add your Gemfile, run bundle install

and add your source code.

The real point of the command onbuild

is that it allows the image to be used as a base image, but still execute certain commands that it could not do before. In the Rails example, the image onbuild

doesn't know your specific code. However, you can use the image onbuild

as a base (i.e. FROM rails:onbuild

) and it will run commands onbuild

before executing new commands that you list in your own Dockerfile.

+4


source







All Articles