Getting Started with Compose

Get introduced to a different, higher-level tool that lets us coordinate and manage containers for the different services that make up our application.

Docker Compose

Docker Compose, or just Compose for short, is a tool for managing an application that needs several different containers to work together. Compose is declarative; you describe each part of your application known as a service and Compose handles the grunt work of ensuring the right containers are run when and how you need.

It also manages to create and destroy the resources needed for the app. For example, it creates a separate, private network for your application, giving you a predictable, isolated environment. It also plays a key role in how we deploy and scale applications with Docker.

Compose is designed with developers in mind. It lets us interact with our application in terms of concepts that we are familiar with, for example, “run our web service” or “stop the database”. This is in stark contrast to the low-level docker run commands we have seen, where the context of what we are trying to achieve is harder to see. Before we can get Compose to do our bidding, though, we first have to describe our application by creating a docker-compose.yml file. This does not replace the need for Dockerfiles—blueprints for creating containers—but it describes what images our app requires and how they are run in concert.

Making docker-compose.yml

Here is an initial docker-compose.yml for our Rails project:

Get hands-on with 1200+ tech skills courses.