0
0
Dockerdevops~30 mins

Why Docker Compose simplifies multi-container apps - See It in Action

Choose your learning style9 modes available
Why Docker Compose simplifies multi-container apps
📖 Scenario: You want to run a simple web app that needs two parts: a web server and a database. Managing each part separately is hard and slow.Docker Compose helps you start both parts together with one command.
🎯 Goal: Build a Docker Compose setup that runs a web server and a database together easily.
📋 What You'll Learn
Create a docker-compose.yml file with two services: web and db
Set the web service to use the nginx:latest image
Set the db service to use the mysql:5.7 image with environment variables
Use Docker Compose commands to start and show running containers
💡 Why This Matters
🌍 Real World
Many apps need multiple parts like a web server and database. Docker Compose helps run them together easily.
💼 Career
DevOps engineers use Docker Compose to manage multi-container apps during development and testing.
Progress0 / 4 steps
1
Create the initial Docker Compose file
Create a file named docker-compose.yml with a version set to '3.8' and an empty services section.
Docker
Need a hint?

The version key defines the Compose file format version. The services section will hold your app parts.

2
Add the web and db services
Add two services under services: web using image nginx:latest and db using image mysql:5.7.
Docker
Need a hint?

Indent the services properly under services. Use image to specify the container image.

3
Configure environment variables for the db service
Under the db service, add an environment section with MYSQL_ROOT_PASSWORD set to example.
Docker
Need a hint?

Environment variables are set as key-value pairs under environment.

4
Start the app and check running containers
Run docker-compose up -d to start the services in the background, then run docker-compose ps to list running containers.
Docker
Need a hint?

Use docker-compose up -d to start containers quietly in the background. Use docker-compose ps to see their status.