Home Explore Blog CI



docker

1st chunk of `content/get-started/docker-concepts/the-basics/what-is-docker-compose.md`
0a014b256587306367ad38eade12b3df2dc0369e11bdf2c90000000100000dee
---
title: What is Docker Compose?
weight: 40
keywords: concepts, build, images, container, docker desktop
description: What is Docker Compose?
aliases:
 - /guides/walkthroughs/multi-container-apps/
 - /guides/docker-concepts/the-basics/what-is-docker-compose/
---

{{< youtube-embed xhcUIK4fGtY >}}

## Explanation

If you've been following the guides so far, you've been working with single container applications. But, now you're wanting to do something more complicated - run databases, message queues, caches, or a variety of other services. Do you install everything in a single container? Run multiple containers? If you run multiple, how do you connect them all together?

One best practice for containers is that each container should do one thing and do it well. While there are exceptions to this rule, avoid the tendency to have one container do multiple things.

You can use multiple `docker run` commands to start multiple containers. But, you'll soon realize you'll need to manage networks, all of the flags needed to connect containers to those networks, and more. And when you're done, cleanup is a little more complicated.

With Docker Compose, you can define all of your containers and their configurations in a single YAML file. If you include this file in your code repository, anyone that clones your repository can get up and running with a single command.

It's important to understand that Compose is a declarative tool - you simply define it and go. You don't always need to recreate everything from scratch. If you make a change, run `docker compose up` again and Compose will reconcile the changes in your file and apply them intelligently.

> **Dockerfile versus Compose file**
>
> A Dockerfile provides instructions to build a container image while a Compose file defines your running containers. Quite often, a Compose file references a Dockerfile to build an image to use for a particular service.


## Try it out 

In this hands-on, you will learn how to use a Docker Compose to run a multi-container application. You'll use a simple to-do list app built with Node.js and MySQL as a database server.

### Start the application

Follow the instructions to run the to-do list app on your system.

1. [Download and install](https://www.docker.com/products/docker-desktop/) Docker Desktop.
2. Open a terminal and [clone this sample application](https://github.com/dockersamples/todo-list-app).

    ```console
    git clone https://github.com/dockersamples/todo-list-app 
    ```

3. Navigate into the `todo-list-app` directory:

    ```console
    cd todo-list-app
    ```

    Inside this directory, you'll find a file named `compose.yaml`. This YAML file is where all the magic happens! It defines all the services that make up your application, along with their configurations. Each service specifies its image, ports, volumes, networks, and any other settings necessary for its functionality. Take some time to explore the YAML file and familiarize yourself with its structure. 

4. Use the [`docker compose up`](/reference/cli/docker/compose/up/) command to start the application:

    ```console
    docker compose up -d --build
    ```

    When you run this command, you should see an output like this:

    ```console
    [+] Running 5/5
    ✔ app 3 layers [⣿⣿⣿]      0B/0B            Pulled          7.1s
      ✔ e6f4e57cc59e Download complete                          0.9s
      ✔ df998480d81d Download complete                          1.0s
      ✔ 31e174fedd23 Download complete                          2.5s

Title: Introduction to Docker Compose
Summary
Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to define all your containers and their configurations in a single YAML file. This makes it easier to manage networks and connect containers. A Dockerfile provides instructions to build a container image, while a Compose file defines your running containers.