Day 19 Task: Docker for DevOps Engineers part-3

Day 19 Task: Docker for DevOps Engineers part-3

Docker-Volume & Docker Networks

#Docker-Volume

-Docker volumes are file systems mounted on Docker containers to preserve data generated by the running container.

-The data doesn't persist when that container no longer exists, and it can be difficult to get the data out of the container if another process needs it.

-Volumes are the preferred mechanism for persisting data generated by and used by Docker containers. While bind mounts are dependent on the directory structure and OS of the host machine, volumes are completely managed by Docker.

#Docker- Networking

-Docker networking allows you to attach a container to as many networks as you like.

-You can also attach an already-running container. Go ahead and attach your running web app to my_bridge.

-There are three common Docker network types – bridge networks, used within a single host, overlay networks, for multi-host communication, and macvlan networks which are used to connect Docker containers directly to host network interfaces.

-Container networking allows containers to communicate with other containers or hosts to share resources and data. Modern container networking aims to standardize and optimize container data flows, creating zones of isolation that allow large numbers of containers to communicate efficiently and securely.

#task1

i). 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)

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

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

  • also add replicas in the deployment file for auto-scaling.

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

#Task-2

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

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

iii). Verify that the data is the same in all containers by using the docker exec command to run commands inside each container.

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

i). Create a Docker volume:

sudo docker volume create my_volume

ii). Volume inspect

docker volume inspect mt_volume

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

iv). Verify that the data is the same in all containers by using the docker exec command to run commands inside each container.

verification

% docker exec -it 7708dbcd7b22 sh

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

-docker volume ls

-docker stop 7708dbc7b22

-docker volume rm 7708dbc7b22

-docker volume rm my_volume