---
title: Multi container apps
weight: 70
linkTitle: "Part 6: Multi-container apps"
keywords: get started, setup, orientation, quickstart, intro, concepts, containers,
docker desktop
description: Using more than one container in your application
aliases:
- /get-started/07_multi_container/
- /guides/workshop/07_multi_container/
---
Up to this point, you've been working with single container apps. But, now you will add MySQL to the
application stack. The following question often arises - "Where will MySQL run? Install it in the same
container or run it separately?" In general, each container should do one thing and do it well. The following are a few reasons to run the container separately:
- There's a good chance you'd have to scale APIs and front-ends differently than databases.
- Separate containers let you version and update versions in isolation.
- While you may use a container for the database locally, you may want to use a managed service
for the database in production. You don't want to ship your database engine with your app then.
- Running multiple processes will require a process manager (the container only starts one process), which adds complexity to container startup/shutdown.
And there are more reasons. So, like the following diagram, it's best to run your app in multiple containers.

## Container networking
Remember that containers, by default, run in isolation and don't know anything about other processes
or containers on the same machine. So, how do you allow one container to talk to another? The answer is
networking. If you place the two containers on the same network, they can talk to each other.
## Start MySQL
There are two ways to put a container on a network:
- Assign the network when starting the container.
- Connect an already running container to a network.
In the following steps, you'll create the network first and then attach the MySQL container at startup.
1. Create the network.
```console
$ docker network create todo-app
```
2. Start a MySQL container and attach it to the network. You're also going to define a few environment variables that the
database will use to initialize the database. To learn more about the MySQL environment variables, see the "Environment Variables" section in the [MySQL Docker Hub listing](https://hub.docker.com/_/mysql/).
{{< tabs >}}
{{< tab name="Mac / Linux / Git Bash" >}}
```console
$ docker run -d \
--network todo-app --network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:8.0
```
{{< /tab >}}
{{< tab name="PowerShell" >}}
```powershell
$ docker run -d `
--network todo-app --network-alias mysql `
-v todo-mysql-data:/var/lib/mysql `
-e MYSQL_ROOT_PASSWORD=secret `
-e MYSQL_DATABASE=todos `
mysql:8.0
```
{{< /tab >}}
{{< tab name="Command Prompt" >}}
```console
$ docker run -d ^
--network todo-app --network-alias mysql ^
-v todo-mysql-data:/var/lib/mysql ^
-e MYSQL_ROOT_PASSWORD=secret ^
-e MYSQL_DATABASE=todos ^
mysql:8.0
```
{{< /tab >}}
{{< /tabs >}}
In the previous command, you can see the `--network-alias` flag. In a later section, you'll learn more about this flag.
> [!TIP]
>
> You'll notice a volume named `todo-mysql-data` in the above command that is mounted at `/var/lib/mysql`, which is where MySQL stores its data. However, you never ran a `docker volume create` command. Docker recognizes you want to use a named volume and creates one automatically for you.
3. To confirm you have the database up and running, connect to the database and verify that it connects.
```console
$ docker exec -it <mysql-container-id> mysql -u root -p