Day 19 Task: Docker for DevOps Engineers

Day 19 Task: Docker for DevOps Engineers

Till now you have learned how to create the docker-compose.yml file and pushed it to the Repository. Let's move forward and dig more on other Docker-compose.yml concepts. Aaj thodi padhai krte hai on Docker Volume & Docker Network 😃

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 same data. reference

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

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 )

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

    Steps:

    1. Clone the repository in your local using command “git clone <remote url>”

      2. install docker-compose sudo apt-get install docker-compose

      1. make a docker-compose.yaml file and use the command docker-compose up

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674582372378/984870d1-0c3e-4325-be62-b19170ff44ac.png align="center")

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674582394307/338d8ec9-b7fd-4dc2-9039-ccac31dcd8d0.png align="center")

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674582417849/26c9110c-c13f-40b0-8c75-31010c3fb918.png align="center")

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674582587859/e5a435cb-8707-47e8-a6b1-6078b9e7e13f.png align="center")

    Use the `docker-compose scale` command to increase or decrease the number of replicas for a specific service. You can also add [`replicas`](https://stackoverflow.com/questions/63408708/how-to-scale-from-within-docker-compose-file) in deployment file for *auto-scaling*.

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674583157810/76a54058-a490-4cfd-9d45-afc4d342b00b.png align="center")

    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.

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674583273716/ac49321b-4648-457d-9092-d540c437c0fe.png align="center")

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674583311487/cb4b6ff5-a651-4301-a686-e875bafc8edc.png align="center")

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674583335261/c5cd2400-0f41-4f0a-b084-f3c534917b20.png align="center")

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

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674583458518/b612dec1-af80-4748-b99a-8d8441807f0a.png align="center")

    # **<mark>Task-2</mark>**


Make a volume of “**todo-react-docker”** container.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674584394549/45e7e801-6575-4fef-80b1-acd838d2bd90.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674584607841/d4300739-ba09-4278-b3bd-ff73b9328a31.png align="center")

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

    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674584790872/64c410a4-b531-4848-917a-c740c4de9ca0.png align="center")

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

        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1674584844025/5e7184df-f5bc-4978-b8a7-636bde8f5d53.png align="center")

        Thank you for reading this blog. Hope it helps.

        \_\_ Safia Khatoon