Day 19 Task: Docker for DevOps Engineers

Day 19 Task: Docker for DevOps Engineers

Docker-Volume

Docker Volumes:

Docker volumes are a widely used and useful tool for ensuring data persistence while working in containers. 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.

  • A container's writable layer is tightly coupled to the host machine where the container is running. The data cannot be easily moveable somewhere else.

  • Writing into a container's writable layer requires a storage driver to manage the filesystem.

Docker has two options for containers to store files in the host machine so that the files are persisted even after the container stops:

  1. Volumes are stored in a part of the host filesystem, which is managed by

  2. Bind mounts may be stored anywhere on the host system.

The volumes are stored on the host, independent of the container life cycle. This allows users to back up data and share file systems between containers easily.

Docker automatically creates a directory for the volume on the host under the /var/lib/docker/volume/path.

Docker Network:

What is Docker Networking?

Docker networking enables a user to link a Docker container to as many networks as he/she requires. Docker Networks are used to provide complete isolation for Docker containers.

Note: A user can add containers to more than one network.

Advantages of Docker Networking

Some of the major benefits of using Docker Networking are:

  • They share a single operating system and maintain containers in an isolated environment.

  • It requires fewer OS instances to run the workload.

  • It helps in the fast delivery of software.

  • It helps in application portability.

How Does Docker Networking Work?

For a more in-depth understanding, let’s have a look at how Docker Networking works. Below is a diagrammatic representation of the Docker Networking workflow:

Docker Networking Working

TASK1:

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

  • 1.Created django_todo_app container

  • 2.Created mysqldb database container

  • Created docker compose.yml file for both the containers in single file like below.

  • 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 deployment file for auto-scaling.

  • docker-compose up --scale web=2 can be done by this command or also replica in deployment file.

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

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

TASK2:

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

Make sure target path before mount.

SOURCE=PWD from path

Target=to workdirectory.

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

Created 2 containers names:

Created files in Container2(app folder i.e.workdirectory which i provided name in dockerfile under WORKDIR)

exit (/app is the workdir for docker like pwd in linux)

Exit from container and verified if files reflected in target path

Again created container 3 with same image and created file 9 in this(It is reflecting all the files which we created in container 2)

Now again will stop container3 and jump on container2 will make sure if file9 has refelcted in container2 or not,so data from both the containers is same.

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.

Docker start/docker attach:

Docker stop:

Thank you for reading!! Hope you find this helpful.

#day19#90daysofdevops#devopscommunity#

Always open for suggestions..!!

Thank you Shubham Londhe !