Docker Compose is Docker's multi-service container manager that acts as a project coordinator for your containers, allowing you to define services, networks, and volumes in a single YAML file and start them with a single command
docker-compose up
Key points
One file for everything describes the complete configuration of your application in docker-compose.yml
Multi-container orchestration runs multiple containers together, for example application plus database plus cache
Easy to share the YAML file is portable and anyone can run your stack with docker-compose up
Integrated networks containers can communicate with each other by service name
What is YAML
YAML is pronounced yah-mull and is a human-readable way to write structured data; it is a less verbose alternative to JSON or XML and is designed for data, not documents
Why YAML is popular
Easy to read without unnecessary braces or quotes
Indentation-based uses spaces for hierarchy similar to Python
Supports comments using the number sign symbol
Widely used in DevOps tools such as Docker Compose, Kubernetes, GitHub Actions, Ansible, and others adopt YAML
Prerequisites
Make sure Docker is installed and running
Docker Compose installed, check with
docker-compose --version
Use a Linux machine or WSL Ubuntu to follow this tutorial
Task 1 Learn to use docker-compose.yml
Step 1 Create the project directory
mkdir flask-docker-compose cd flask-docker-compose
Step 2 Create your Flask application
mkdir app cd app touch app.py requirements.txt
Basic example of app.py
from flask import Flask app = Flask(__name__) @app.route(/) def home(): return Hello from Flask with Docker Compose! if __name__ == __main__ app.run(host=0.0.0.0, port=5000)
Step 3 Create a Dockerfile in the root directory flask-docker-compose
Simple example of Dockerfile
FROM python:3.12-slim WORKDIR /app COPY app/ /app/ RUN pip install -r requirements.txt EXPOSE 5000 CMD python app.py
Step 4 Create docker-compose.yml in the root
Basic example of docker-compose version 3 services web build . ports - 5000:5000 environment - FLASK_ENV=development
Step 5 Run the application with Docker Compose
docker-compose up
Open the browser at https://localhost:5000 and you should see Hello from Flask with Docker Compose!
Task 2 Download a public image and run it locally
Step 1 Download a prebuilt image, for example Nginx
docker pull nginx
Step 2 Run the Nginx container
docker run -d --name mynginx -p 8080:80 nginx
Visit https://localhost:8080 to verify that Nginx responds
Step 3 Run as non-root user option in case of permission errors
If there are permission errors, you can add your user to the docker group and restart with
sudo usermod -aG docker $USER reboot
Step 4 Inspect the container
docker inspect mynginx
Look for fields such as ExposedPorts, Mounts, and State
Step 5 View logs
docker logs mynginx
Step 6 Stop and start the container
docker stop mynginx docker start mynginx
Step 7 Remove the container when you no longer need it
docker rm -f mynginx
About Q2BSTUDIO
Q2BSTUDIO is a software development company that offers custom applications and custom software for clients looking for solutions tailored to their needs. We are specialists in artificial intelligence, cybersecurity, aws and azure cloud services, business intelligence services, and Power BI implementations. We develop AI solutions for companies, including AI agents and automation platforms that improve processes and productivity.
Featured services
Custom application development and custom software, integration with aws and azure cloud services, artificial intelligence projects, implementation of AI agents, cybersecurity to protect infrastructures, and business intelligence services with Power BI and other tools
Why choose us
Experience in complex projects, personalized approach for each client, and specialization in emerging technologies such as artificial intelligence and AI for companies. We offer consulting, security, and cloud deployment to accelerate the digital transformation of your organization.
If you need help putting your stacks into production with Docker Compose or want to develop a custom application with artificial intelligence and cybersecurity capabilities, contact Q2BSTUDIO for a consultation and personalized proposal



