...

/

Docker Compose and MySQL

Docker Compose and MySQL

Learn how to launch multiple containers using Compose.

Launch multiple containers with Docker Compose

Starting Docker containers individually is not fun, especially when commands are long and difficult to remember. Fortunately, Docker Compose provides a way to build and launch containers, networks, and volumes from a single configuration file named docker-compose.yml.

YAML is a cheeky mnemonic for YAML Ain’t Markup Language, a common, compact data format often used for configuration purposes. It uses new lines and tab stops rather than the quotes and brackets favored by JSON.

Docker Compose offers many configuration options, but an example is the best way to illustrate common settings. Let’s consider following docker-compose.yml:

Press + to interact
version: '3'
services:
mysql:
image: mysql
container_name: mysql
environment:
- MYSQL_ROOT_PASSWORD=mysecret
volumes:
- mysqldata:/var/lib/mysql
ports:
- "3000:3306"
networks:
- mysqlnet
restart: on-failure
adminer:
image: adminer
container_name: adminer
depends_on:
- mysql
ports:
- "8080:8080"
networks:
- mysqlnet
restart: on-failure
volumes:
mysqldata:
networks:
mysqlnet:

This creates identical containers to the docker run commands you used earlier with the volumes and networks listed at the bottom. It also defines two new ...