In the previous article we learned how to create a Rails 6 Docker image and run it locally. While useful for demonstration purposes, it is not enough for a real-world web application. In addition to our main application code, there are other services that we also need, like a database, a queue system, storage and so on.
Docker Compose provides a way for us to describe how our entire application works using declarative code. Declarative code means that we specify the final state of our application, rather than specifying what steps are needed to create our application. This results in a simpler, more intuitive configuration.
Just like we used a Dockerfile to instruct Docker on how to create our custom image, we use a docker-compose.yml file when using Compose.
First, let’s take a look at a sample Compose file for a Rails 6 application: