๐Ÿ“‹ Day 18 Task: Docker for DevOps Engineers ๐Ÿณ

ยท

3 min read

Table of contents

No heading

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:

  1. 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
    
  2. Inspect the container's running processes and exposed ports:

     docker inspect container_id
    
  3. View the container's log output:

     docker logs container_id
    
  4. Stop and start the container:

     docker stop container_id
     docker start container_id
    
  5. 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! ๐Ÿณโœจ

ย