0
0
Dockerdevops~30 mins

docker compose up and down - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Docker Compose to Start and Stop Containers
📖 Scenario: You are working on a small web application that uses two services: a web server and a database. You want to manage these services easily using Docker Compose.
🎯 Goal: Learn how to write a simple docker-compose.yml file to define two services, then use docker compose up to start them and docker compose down to stop and remove them.
📋 What You'll Learn
Create a docker-compose.yml file with two services: web and db
The web service uses the nginx:latest image
The db service uses the mysql:5.7 image
Use docker compose up to start the services
Use docker compose down to stop and remove the services
💡 Why This Matters
🌍 Real World
Docker Compose is widely used to manage multi-container applications easily on a developer's machine or in testing environments.
💼 Career
Knowing how to use Docker Compose is essential for DevOps roles to automate and manage containerized applications efficiently.
Progress0 / 4 steps
1
Create the docker-compose.yml file with two services
Create a file named docker-compose.yml with two services: web using the image nginx:latest and db using the image mysql:5.7. Use version '3.8' at the top.
Docker
Need a hint?

Start with version: '3.8', then add services with web and db keys and their images.

2
Add environment variable for MySQL root password
Add an environment variable MYSQL_ROOT_PASSWORD with value example under the db service in docker-compose.yml.
Docker
Need a hint?

Under db, add environment: and then MYSQL_ROOT_PASSWORD: example.

3
Start the services using docker compose up
Run the command docker compose up -d in the terminal to start the web and db services in detached mode.
Docker
Need a hint?

Use docker compose up -d to start services in the background.

4
Stop and remove the services using docker compose down
Run the command docker compose down in the terminal to stop and remove the web and db services.
Docker
Need a hint?

Use docker compose down to stop and clean up the containers.