Day 18 Task: Docker for DevOps Engineers

Greetings! 👋 I'm Priyadarshi Ranjan, a dedicated DevOps Engineer embarking on an enriching journey. Join me as I delve into the dynamic realms of cloud computing and DevOps through insightful blogs and updates. 🛠️ My focus? Harnessing AWS services, optimizing CI/CD pipelines, and mastering infrastructure as code. Whether you're peers, interns, or curious learners, let's thrive together in the vibrant DevOps ecosystem. 🌐 Connect with me for engaging discussions, shared insights, and mutual growth opportunities. Let's embrace the learning curve and excel in the dynamic realm of AWS and DevOps technology!
Introduction
Welcome to Day 18 of our 90-day DevOps journey! So far, we've created Dockerfiles and pushed them to repositories. Today, we're diving deeper into Docker by exploring Docker Compose. Let's understand what Docker Compose is and how it can make managing multi-container applications a breeze. 😃
Docker Compose
Docker Compose is a tool designed to help define and manage multi-container Docker applications. With Compose, you can create a YAML file to define your services and, with a single command, spin everything up or tear it all down. This simplifies the process of managing interconnected containers.
What is YAML?
YAML, which stands for "YAML Ain’t Markup Language" (or "Yet Another Markup Language"), is a data serialization language that's human-readable and commonly used for configuration files. YAML files are easy to understand and use a .yml or .yaml extension.
Task 1: Setting Up with Docker Compose
Your first task is to learn how to use the docker-compose.yml file to set up your environment, configure services, and link different containers. You'll also learn how to use environment variables in the docker-compose.yml file.
Sample docker-compose.yml File
Here's a simple example to get you started:
version: '3'
services:
web:
image: nginx:latest
ports:
- "8080:80"
db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: example
In this example, we define two services: web and db. The web service uses the latest Nginx image and maps port 8080 on the host to port 80 on the container. The db service uses the latest MySQL image and sets an environment variable for the MySQL root password.
Task 2: Running a Pre-existing Docker Image
For the second task, you'll pull a Docker image from a public repository (like Docker Hub) and run it on your local machine. Follow these steps:
Pull the Docker Image:
docker pull nginx:latestRun the Container as a Non-root User: First, give your user permission to Docker:
sudo usermod -aG docker $USERReboot your machine to apply the changes:
sudo rebootRun the Container:
docker run -d --name mynginx -p 8080:80 nginx:latestInspect the Container:
docker inspect mynginxView Container Logs:
docker logs mynginxStop and Start the Container:
docker stop mynginx docker start mynginxRemove the Container:
docker rm mynginx
Conclusion
Docker Compose is a powerful tool that simplifies the management of multi-container Docker applications. By using a simple YAML file, you can define your entire stack and manage it with ease. The skills you've learned today will help you in real-world scenarios where applications often consist of multiple interconnected services.
Real-life Example
Imagine you're working on a web application that consists of a front-end service, a back-end service, and a database. With Docker Compose, you can define all these services in a single docker-compose.yml file and manage them as a cohesive unit. This approach saves time and reduces complexity, making your development process more efficient.
Connect and Follow Me on Socials




