Docker for DevOps Engineers (Part-3)

akash zadeakash zade
3 min read

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

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

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

  1. Clone the repository in the local system using the command git clone then create a Dockerfile and configure it.

  2. Build the image using dockerfile by the command docker build & run the container by docker run command.

  3. Go for the browser & paster public ip:8000 to see the working of application.

  4. Make a volume of the "nodejs-todo-app" container

  5. Make a docker-compose.yml file and configure it.

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

  7. Use the docker-compose scale command to increase or decrease the number of replicas for a specific service. We can also add replicas in the deployment file for auto-scaling.

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

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

Task-2

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

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

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

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

Reference:

Docker-volume

Docker-network


Thanks for reading my blog!

Also for your valuable time.

Keep learning and upskilling.

0
Subscribe to my newsletter

Read articles from akash zade directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

akash zade
akash zade

Hello there👋, I'm Akash Zade and I'm passionate about the world of DevOps. As a curious and dedicated learner🏆, I'm constantly exploring new ways to improve software development and make the process more efficient. With a keen interest 🍁 in cloud computing, containerization, and automation, I'm excited to share my insights and experiences as I navigate the ever-evolving world of DevOps. Join me 🤝 on this awesome journey where technology meets efficiency!