🛥️Day 22 Task: Advanced Docker for DevOps Engineers

🛥️Day 22 Task: Advanced Docker for DevOps Engineers

🛥️Day 22 Task: Advanced Docker for DevOps Engineers

🔨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:

  1. Learn to use the docker-compose.yml file.

  2. Set up the environment, configure services, and link containers.

  3. Use environment variables in the docker-compose.yml file.

Task 2:

  1. Pull and run a pre-existing Docker image.

  2. Run the container as a non-root user.

  3. Reboot the instance.

  4. Inspect running processes and exposed ports.

  5. View container logs.

  6. Stop, start, and remove the container.

Steps:

  1. Pull Docker Image:

      docker pull nginx
    
  2. Give User Permission:

      sudo usermod -aG docker $USER
      sudo reboot
    
  3. Run Container as Non-Root User:

      docker run --name my_container -d -p 8080:80 --user 1000:1000 nginx
    
  4. Inspect Container:

      docker inspect my_container
    
  5. View Logs:

      docker logs my_container
    
  6. Stop Container:

      docker stop my_container
    
  7. Start Container:

      docker start my_container
    
  8. 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! 😊