Day 19 Task: Docker for DevOps Engineers
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. If we want to share that storage space with other containers, we can't do that.
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 )
hints:
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 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
Let's Start with my Mini-Project using the docker-compose.yml file--->
This is a simple voting app developed using Python, Flask, and MySQL. It allows users to vote for their favorite scripting language and displays the vote count for each language in real time. The app is built and deployed using Docker-Compose.
Get the source code for this task
$ git clone
https://github.com/Chaitannyaa/Simple_Docker-Compose-Project.git
Task-2
Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.
Let's take the example of "Django-todo-notes-app" created by Shubham Londhe
$ git clone
https://github.com/Chaitannyaa/django-todo-cicd.git
In a typical Django application (which seems to be the case based on the presence of manage.py, db.sqlite3, and staticfiles), the database file, in this case, db.sqlite3 would be the file that stores the app data.
- Let's create a directory with the data file "volume/store_data/db.sqlite3" in the same directory where docker-compose.yml is located.
- Add this "volume" in ".dockerignore" and add volume mapping inside the "docker-compose.yml" file.
- Run "docker-compose up" and add some data to the app. Then delete the container and again spin the new container with our local volume mapping to confirm data persistency.
Create two or more containers that read and write data to a common volume.
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 the docker volume rm command to remove the volume when you're done.
You can post on LinkedIn and let us know what you have learned from this task by #90DaysOfDevOps Challenge. Happy Learning :)
Day 19 Task is completed!
90DaysOfDevOps Tasks👇