Day 19 Task: Docker-Volume and Docker- network for DevOps Engineers
Docker-Volume:
A Docker volume is a way to store data outside of a Docker container's filesystem. This allows data to persist even if the container is deleted or recreated. Volumes can also be shared among multiple containers and can be backed by various storage drivers, such as local files or network storage. This allows for greater flexibility and control over data storage in a Docker environment.
Docker Network:
Docker network is a feature in Docker that allows containers to communicate with each other and with the host system. It provides a way to create and manage virtual networks for container communication. There are several types of networks that can be created in Docker, including bridge, host, and overlay networks. Each type of network provides different capabilities and can be used for different use cases. For example, a bridge network allows containers on the same host to communicate with each other, while an overlay network allows containers on different hosts to communicate. Additionally, Docker networks can be used to configure network settings such as IP addresses, ports, and DNS.
Task-1:
Create a multi-container docker-compose file which will bring UP and bring DOWN containers in a single shot (Example - Create application and database container)
- The docker-compose up command with the -d flag is used to start and run a multi-container application defined in a docker-compose.yml file in detached mode. The -d flag stands for "detached" mode and it runs the container in the background'
.
- The docker-compose scale command is used to adjust the number of containers for a service defined in a docker-compose.yml file. This command allows you to easily scale the number of containers running for a particular service, which can be useful for handling changes in traffic or load.
- The docker-compose ps command is used to list the containers that are running for a multi-container application defined in a docker-compose.yml file. This command will display the status of each container, including the container name, service name, and the command that was used to start the container.
- The docker-compose logs command is used to view the logs for all the services defined in a docker-compose.yml file. This command will display the logs for all the running containers for the specified services, in real-time.
- The docker-compose down command is used to stop and remove all the containers, networks, and volumes defined in a docker-compose.yml file. This command will stop and remove all the containers that were created by the docker-compose up command, as well as any networks and volumes that were created for the application.
Task-2:
Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.
Create two or more containers that read and write data to the same volume using the docker run --mount command.
Verify that the data is the same in all containers by using the docker exec command to run commands inside each container.
Use the docker volume ls command to list all volumes and docker volume rm command to remove the volume when you're done.