Day 19: Docker Networking for DevOps.

Day 19: Docker Networking for DevOps.

Till now you have learned how to create a docker-compose.yml file and pushed it to the Repository. Let's move forward and dig more into other Docker-compose.yml concepts.

Today we will learn 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 the 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). 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.


Task-1:

  • 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 )

Screenshot from 2023-04-01 20-39-05

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

Screenshot from 2023-04-01 20-39-28

  • Use the docker-compose scale command to increase or decrease the number of replicas for a specific service.

Screenshot from 2023-04-01 20-57-52

  • 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.

Screenshot from 2023-04-01 20-41-20

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

Screenshot from 2023-04-01 21-01-48


Task-2:

  • Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.

Screenshot from 2023-04-01 21-24-43

  • Create two or more containers that read and write data to the same volume using the docker run --mount command.

Screenshot from 2023-04-01 22-07-40

  • Use the docker volume ls command to list all volumes and the docker volume rm command to remove the volume when you're done.

Screenshot from 2023-04-01 21-24-43

Screenshot from 2023-04-01 22-20-26

  • We can verify the volumes are connected are not and running on the required port.

Screenshot from 2023-04-01 22-22-53

Screenshot from 2023-04-01 22-23-13

Screenshot from 2023-04-01 22-24-54


Happy Learning :)

Did you find this article valuable?

Support DevOps by becoming a sponsor. Any amount is appreciated!