0
0
Dockerdevops~15 mins

Defining services in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Defining Services with Docker Compose
📖 Scenario: You are setting up a simple web application using Docker. You want to define the services your app needs in a docker-compose.yml file.This will help you start all parts of your app with one command.
🎯 Goal: Create a docker-compose.yml file that defines two services: a web server and a database.The web server will use the nginx:latest image, and the database will use the mysql:5.7 image.
📋 What You'll Learn
Create a docker-compose.yml file
Define a service called web using the nginx:latest image
Define a service called db using the mysql:5.7 image
Add environment variables for the db service: MYSQL_ROOT_PASSWORD set to example
Print the final docker-compose.yml content
💡 Why This Matters
🌍 Real World
Docker Compose is used to run multi-container Docker applications easily by defining all services in one file.
💼 Career
Knowing how to define services in Docker Compose is essential for DevOps roles to manage application environments efficiently.
Progress0 / 4 steps
1
Create the base structure of docker-compose.yml
Create a docker-compose.yml file with the version set to "3.8" and an empty services section.
Docker
Need a hint?

Start by writing version: "3.8" at the top, then add services: below it.

2
Define the web service using the nginx:latest image
Add a service called web under services that uses the image nginx:latest.
Docker
Need a hint?

Indent the web service under services, then add image: nginx:latest under web.

3
Define the db service using the mysql:5.7 image with environment variables
Add a service called db under services that uses the image mysql:5.7 and has an environment variable MYSQL_ROOT_PASSWORD set to example.
Docker
Need a hint?

Indent the db service under services. Add image: mysql:5.7 and then add an environment section with MYSQL_ROOT_PASSWORD: example.

4
Print the complete docker-compose.yml content
Print the entire content of the docker-compose.yml file exactly as defined in previous steps.
Docker
Need a hint?

Use a multi-line string variable to hold the content and print it exactly.