0
0
Dockerdevops~30 mins

Multiple Compose files (override) in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Multiple Docker Compose Files to Override Settings
๐Ÿ“– Scenario: You are working on a web application that uses Docker Compose to run a web server and a database. You want to create a base Compose file for the common setup and an override Compose file to change the web server's port for development.
๐ŸŽฏ Goal: Learn how to create and use multiple Docker Compose files to override service settings without changing the base configuration.
๐Ÿ“‹ What You'll Learn
Create a base Docker Compose file named docker-compose.yml with a web and db service
Create an override Docker Compose file named docker-compose.override.yml to change the web service port
Use the docker compose command to start the services with the override applied
Verify the web service is running on the new port
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
In real projects, multiple Compose files let developers keep a stable base setup and customize it for different environments like development, testing, or production without duplicating all settings.
๐Ÿ’ผ Career
Understanding how to use multiple Docker Compose files is important for DevOps roles to manage containerized applications efficiently and maintain clean, reusable configurations.
Progress0 / 4 steps
1
Create the base Docker Compose file
Create a file named docker-compose.yml with two services: web using the image nginx:alpine and db using the image postgres:alpine. Set the web service to expose port 80.
Docker
Need a hint?

Use the services key to define both web and db services with their images and ports.

2
Create the override Docker Compose file
Create a file named docker-compose.override.yml that overrides the web service port to 8080 instead of 80.
Docker
Need a hint?

Only include the web service and override the ports key to map port 8080 on the host to port 80 in the container.

3
Start the services using both Compose files
Run the docker compose command to start the services using both docker-compose.yml and docker-compose.override.yml files together.
Docker
Need a hint?

Use docker compose up -d to start the services in detached mode. Docker Compose automatically uses both files if named docker-compose.yml and docker-compose.override.yml.

4
Verify the web service is running on port 8080
Run the command docker compose ps and check that the web service is mapped to port 8080 on the host.
Docker
Need a hint?

Use docker compose ps to list running containers and their port mappings. Look for 0.0.0.0:8080->80/tcp under the web service.