...

/

A Default Command

A Default Command

We will learn to modify the Dockerfile according to our requirements.

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:

 ...