Day 19 Task: Exploring Docker Volume and Network Concepts

Day 19 Task: Exploring Docker Volume and Network Concepts

ยท

3 min read

This is #90DaysofDevops challenge under the guidance of Shubham Londhe sir.

  • Welcome back to our DevOps journey! Today, we'll dive deeper into Docker Volume and Docker Network concepts, enhancing your proficiency with Docker-compose.yml. Let's explore each task with practical examples and easy-to-understand commands.

Understanding Docker Volume

  • Docker volumes provide separate storage areas accessible by containers, enabling us to store critical data outside the container's scope. Let's explore our docker-compose.yml file with an illustrative example:
version: '3'

services:
  web:
    image: supriya279/quiz-app-new1:latest
    ports:
      - "5000:5000"  # Map container port 5000 to host port 5001 for the first container
      - "6007:7000"  # Map container port 6001 to host port 5002 for the second container
      - "6005:6000"  # Map container port 6002 to host port 5003 for the third container
    restart: always
    environment:
      - FLASK_APP=app.py
      - FLASK_ENV=development
    volumes:
      - webvolume:/data
  db:
    image: mysql:latest
    ports:
      - "3306:3306"
    environment:
      - "MYSQL_ROOT_PASSWORD=test@123"

volumes:
  webvolume:

In this docker-compose.yml file:

  • We define two services: web for our web application and db for the database.

  • The web service exposes port 5000, allowing access to the application.

  • The db service exposes port 3306 for database connectivity.

  • Both services are configured with specific environment variables for smooth operation.

Exploring Docker Network

  • Docker empowers you to create virtual networks, enabling seamless communication between containers and with the host machine. Containers running within the same network can effortlessly exchange information and resources, fostering a cohesive and interconnected environment. Unlike containers' isolated storage spaces, Docker networks provide a shared space for containers to interact and collaborate.

Task-1: Creating a Multi-Container Docker-Compose File

Let's follow these steps:

  • Launch the multi-container application in detached mode:

      docker-compose up -d
    

  • Scale the services as needed:

      docker-compose scale web=3
    

  • This command scales the web service to have three replicas. You can adjust the number as per your requirements for load balancing or redundancy.

  • Monitor container statuses:

      docker-compose ps
    

  • View logs for a specific service:

      docker-compose logs <service_name>
    

  • Stop and remove all containers:

      docker-compose down
    

Task-2: Harnessing Docker Volumes and Named Volumes

Here's how to accomplish this task:

  1. Create containers interacting with a shared volume:

     docker run --mount source=myvolume,target=/data myimage
    

  2. Verify data consistency across containers:

     docker exec <container_id> ls /data
    

  3. List all volumes:

     docker volume ls
    

  4. Remove the volume:

     docker volume rm <volume_name>
    

  • Mastering these Docker concepts equips you with powerful tools to manage containerized environments effectively. Stay tuned for more insights and practical tips in our future sessions!
๐Ÿ’ก
Feel free to ask any questions๐Ÿค” in the comments! I would be happy to answer them.
๐Ÿ’ก
If you liked this post, a thumbs up ๐Ÿ‘ would be awesome. Don't forget to hit the follow button for more helpful content. Your support means a lot! ๐Ÿ˜Š

Thanks for reading! ๐Ÿ’š Happy reading!

ย