🔨Table of Content
🐋What is Docker Compose?
🐋What is YAML?
🐋Docker commands for DevOps engineer
✨Tasks:
✨Task 1
✨Task 2
✨Conclusion:
🐋 What is Docker Compose?
Docker Compose is a handy tool that helps you run multiple containers for your applications effortlessly. Imagine you have different parts of your app (like a web server, database, etc.) running in separate containers. Docker Compose lets you manage all these containers easily with just one command.
Control your app stack: Manage services, networks, and storage all in one YAML file.
One command magic: Start all your services with a single command.
Works everywhere: Use it in development, testing, staging, and production.
🐋 What is YAML?
YAML is a simple language for writing data that humans can easily read and write. It's often used for configuration files.
Easy to read: Unlike other formats, YAML is designed to be easy to understand.
Widely used: You'll find it in many programming and automation tools, like Ansible.
Example YAML File:
# Comment: This is a supermarket list using YAML
---
food:
- vegetables: tomatoes
- fruits:
citrics: oranges
tropical: bananas
nuts: peanuts
sweets: raisins
🐋 Docker Commands for DevOps Engineer
Here are some essential Docker Compose commands you should know:
Start Containers:
docker-compose up
Stop and Remove Containers:
docker-compose down
Build Images:
docker-compose build
Start Existing Containers:
docker-compose start
Stop Running Containers:
docker-compose stop
Restart Containers:
docker-compose restart
List Running Containers:
docker-compose ps
Show Logs:
docker-compose logs
Run Command Inside a Container:
docker-compose exec [service_name] [command]
Pull Images:
docker-compose pull
✨ Tasks
Task 1:
Learn to use the
docker-compose.yml
file.Set up the environment, configure services, and link containers.
Use environment variables in the
docker-compose.yml
file.
Task 2:
Pull and run a pre-existing Docker image.
Run the container as a non-root user.
Reboot the instance.
Inspect running processes and exposed ports.
View container logs.
Stop, start, and remove the container.
Steps:
Pull Docker Image:
docker pull nginx
Give User Permission:
sudo usermod -aG docker $USER sudo reboot
Run Container as Non-Root User:
docker run --name my_container -d -p 8080:80 --user 1000:1000 nginx
Inspect Container:
docker inspect my_container
View Logs:
docker logs my_container
Stop Container:
docker stop my_container
Start Container:
docker start my_container
Remove Container:
docker rm my_container
✨ Conclusion
Docker Compose makes managing multiple containers easy using YAML. With basic Docker commands, you can deploy and manage containers effortlessly. Tasks include running images, managing user permissions, and handling container lifecycle.
Happy Learning! 😊