๐ Day 18 Task: Docker for DevOps Engineers ๐ณ
Table of contents
No headings in the article.
Hey there! ๐ We've made great progress so far in our Docker journey. Today, we'll be diving into Docker Compose, a fantastic tool for defining and sharing multi-container applications effortlessly. ๐
๐ Docker Compose: Docker Compose simplifies our lives by allowing us to create a YAML file to define the services needed for our application. With just a single command, we can spin everything up or take it all down! ๐ If you want to learn more about Docker Compose, check it out here: Docker Compose Documentation
๐ What is YAML? Before we jump into Docker Compose, let's take a quick look at YAML. YAML is a data serialization language used for configuration files. Some say it stands for "yet another markup language," but we prefer "YAML ain't markup language," emphasizing its focus on data, not documents. ๐ YAML is beloved for being human-readable and easy to understand. YAML files have .yml or .yaml extensions. If you're curious, you can read more about it here: YAML Documentation
๐ป Task-1: Docker Compose Configuration In this task, we will use the docker-compose.yml file to set up the environment, configure services, and establish links between different containers. We'll also leverage environment variables within the docker-compose.yml file to make things more dynamic and flexible. ๐
Here's a sample docker-compose.yaml file to get you started:
version: '3'
services:
web_app:
image: your-web-app-image:latest
environment:
- DB_HOST=db_server
- DB_PORT=5432
ports:
- "8080:80"
db_server:
image: your-db-image:latest
ports:
- "5432:5432"
๐ Task-2: Playing with Docker Containers For this task, we'll pull an existing Docker image from a public repository, like Docker Hub, and run it on your local machine. Exciting, right? ๐ Here are the steps:
Pull the image and run it as a non-root user:
docker pull your-image-name:tag sudo usermod -a -G docker $USER # Reboot your instance to apply the permission changes
Inspect the container's running processes and exposed ports:
docker inspect container_id
View the container's log output:
docker logs container_id
Stop and start the container:
docker stop container_id docker start container_id
Remove the container when you're done:
docker rm container_id
๐ How to Run Docker Commands Without Sudo? Before you proceed with the tasks, make sure Docker is installed and your system is updated. If you haven't done this yet, refer to the previous tasks. To run Docker commands without sudo, execute the following:
sudo usermod -a -G docker $USER
reboot
And there you have it! You're all set to conquer Docker Compose and explore the wonders of Docker containers. ๐ Keep experimenting and happy coding! If you encounter any issues or have questions, feel free to ask. ๐ค
Stay tuned for the next blog update! Happy Dockerizing! ๐ณโจ