0
0
Dockerdevops~15 mins

Depends_on for service ordering in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Depends_on for service ordering
📖 Scenario: You are setting up a simple multi-service application using Docker Compose. One service depends on another to start first. For example, a web app needs the database to be ready before it starts.
🎯 Goal: You will create a docker-compose.yml file that defines two services: db and web. You will use depends_on to ensure the web service starts only after the db service.
📋 What You'll Learn
Create a docker-compose.yml file with two services: db and web.
Set the db service to use the official postgres image.
Set the web service to use the official nginx image.
Use depends_on in the web service to depend on db.
Print the content of the docker-compose.yml file to verify the setup.
💡 Why This Matters
🌍 Real World
Many applications use multiple services like databases and web servers. Docker Compose helps start them in the right order.
💼 Career
Understanding service dependencies is important for DevOps roles to ensure reliable application deployment and startup.
Progress0 / 4 steps
1
Create the basic docker-compose.yml structure
Create a file named docker-compose.yml and add the version '3.8' and an empty services section.
Docker
Need a hint?

Start with the version line and then add the services key with no services yet.

2
Add the db service using the postgres image
Under services, add a service named db that uses the image postgres.
Docker
Need a hint?

Indent the db service under services and specify the image as postgres.

3
Add the web service using nginx and set depends_on
Under services, add a service named web that uses the image nginx and add depends_on with db as its dependency.
Docker
Need a hint?

Indent the web service under services. Use a list under depends_on with db as the item.

4
Print the docker-compose.yml content
Print the entire content of the docker-compose.yml file exactly as created.
Docker
Need a hint?

Use a single print statement with the exact content including indentation and new lines.