0
0
Dockerdevops~15 mins

Compose file versioning in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Compose file versioning
📖 Scenario: You are setting up a Docker Compose file to run a simple web application. You want to specify the version of the Compose file format to ensure compatibility with your Docker environment.
🎯 Goal: Create a Docker Compose file with a specific version, add a service configuration, and display the version used.
📋 What You'll Learn
Create a Docker Compose file with version '3.8'
Add a service named 'web' using the 'nginx:latest' image
Print the Compose file version to confirm
💡 Why This Matters
🌍 Real World
Docker Compose files are used to define and run multi-container Docker applications. Specifying the version ensures compatibility with Docker features.
💼 Career
Understanding Compose file versioning helps in configuring containerized applications reliably, a key skill for DevOps roles.
Progress0 / 4 steps
1
Create the Compose file with version
Create a dictionary called compose_file with a key version set to the string '3.8'.
Docker
Need a hint?

Use a Python dictionary with the key 'version' and value '3.8'.

2
Add a service configuration
Add a key services to the compose_file dictionary. Set it to a dictionary with a key web whose value is another dictionary with the key image set to 'nginx:latest'.
Docker
Need a hint?

Remember to nest dictionaries for services and the web service configuration.

3
Access the Compose file version
Create a variable called version_used and set it to the value of the version key in the compose_file dictionary.
Docker
Need a hint?

Use dictionary key access to get the version value.

4
Print the Compose file version
Write a print statement to display the text "Compose file version: " followed by the value of version_used.
Docker
Need a hint?

Use string concatenation or f-string to combine the text and variable.