Day 19 Task: Docker for DevOps Engineers

Day 19 Task: Docker for DevOps Engineers

ยท

3 min read

Exploring Docker volume, Docker Network

Docker-Volume

Docker allows you to create something called volumes. Volumes are like separate storage areas that can be accessed by containers. They allow you to store data, like a database, outside the container, so it doesn't get deleted when the container is deleted. You can also mount from the same volume and create more containers having same data.

Docker Network

Docker allows you to create virtual spaces called networks, where you can connect multiple containers (small packages that hold all the necessary files for a specific application to run) together. This way, the containers can communicate with each other and with the host machine (the computer on which the Docker is installed). When we run a container, it has its own storage space that is only accessible by that specific container. If we want to share that storage space with other containers, we can't do that.

๐Ÿ”ถTask-1: multi-container docker-compose file

  • Create a multi-container docker-compose file that will bring UP and bring DOWN containers in a single shot ( Example - Create application and database container )

  • git clone from

Use the docker-compose up command with the -d flag to start a multi-container application in detached mode.

#To start the multi-container
docker-compose up -d

Use the docker-compose ps command to view the status of all containers, and docker-compose logs to view the logs of a specific service.

#To view the status
docker-compose ps

Use the docker-compose down command to stop and remove all containers, networks, and volumes associated with the application

#To stop the container
docker-compose down

๐Ÿ”ถ Task-2: Docker Volumes

  • Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.
#To create docker volume
docker volume create --name django-app-volume --opt type=none --opt device=/home/ubuntu/docker_projects/volume --opt o=bind

  • Create two or more containers that read and write data to the same volume using the docker run --mount command.
#mount
docker run -d --mount source=django-app-volume,target=/data -p 8000:8000 django-app:latest

  • Verify that the data is the same in all containers by using the docker exec command to run commands inside each container.
#Docker exec -it <container-id> bash
docker exec -it e497f8de99c bash
  • Use the docker volume ls command to list all volumes and the docker volume rm command to remove the volume when you're done.

In conclusion, Docker volumes play a crucial role in managing data persistence and sharing between containers, especially in multi-container and multi-stage setups. Volumes provide a mechanism to decouple data storage from the container lifecycle, ensuring data integrity, scalability, and easy container management.

If you find my blog valuable, I invite you to like, share, and join the discussion. Your feedback is immensely cherished as it fuels continuous improvement. Let's embark on this transformative DevOps adventure together! ๐Ÿš€ #devops #90daysofdevop #git&github #docker

ย