A Default Command
Explore how to modify your Dockerfile by adding the CMD instruction, which sets a default command to start the Rails server automatically when a container runs. Understand the importance of the Exec form for proper Unix signal handling, and practice building and running your image with these improvements.
We'll cover the following...
Modifying Dockerfile
Currently, every time we want to start a Rails server in a container, we have to explicitly specify the command bin/rails s -b 0.0.0.0 as part of our docker run command. This is a problem because the main purpose of our custom image is to start a Rails server. It would be better if we could embed the knowledge of how to start the Rails server in the image itself.
CMD instruction
We can do this by adding a new instruction to our Dockerfile. The CMD instruction “command,” specifies the default command to run when a container is started from the image. Let’s use this in our Dockerfile to start the Rails server by default: ...