DevOps(Day-19) : Docker for DevOps

DevOps(Day-19) : Docker for DevOps

SPEED1X

TABLE OF CONTENTS

Docker-Volume

Docker allows mounting the filesystems as a volume to the containers. These volumes preserve all the data of the container and the data is persisted even if the container is deleted.

The default path is /var/lib/docker/volumes/ on Linux.

How to use volumes to share data between Docker containers | by Edouard  Courty | Medium

A volume can be mounted to multiple containers and it lies even if all containers are down. It can be removed only manually by the user.

  1. Creating a Docker Volume

    COPY

    COPY

    COPY

    COPY

      $docker volume create [volume_name]
    
  2. Listing a Docker Volume

    COPY

    COPY

    COPY

    COPY

      $docker volume list
    
  3. Mounting a volume.

    COPY

    COPY

    COPY

    COPY

      docker run --mount source=[volume_name],destination=[path_in_container] [docker_image]
    
  4. Removing a Volume.

    COPY

    COPY

    COPY

    COPY

      $docker volume rm [volume_name]
    
  5. Deleting all volumes at once.

    COPY

    COPY

    COPY

    COPY

      $docker volume prune
    

Docker-Network

With Docker-Compose we create multiple containers, in that process, a space is created by Docker where those containers can communicate with each other and the host system. That space is known as Docker Network.

what are the different types of docker networking drivers | Edureka  Community

COPY

COPY

COPY

COPY

$docker network COMMAND

The COMMAND can be connected, create, disconnect, inspect, ls, prune, and rm.

Task - 1

Create a multi-container docker-compose file which will bring UP and bring DOWN containers in a single shot.

  • 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

Task-2

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

    Use the below command to create a volume.

    $ docker volume create --name django-volume-final --opt device=/home/ubuntu/devops/volume/django-volume --opt o=bind --opt type=none django-volume-final

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

    $ docker run -d --name django-notes-app -p 3000:3000 --mount source=django-volume-final,target=/app django-app:v1

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

    $ docker exec -it django-notes-app-V2 /bin/sh

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

Thanks for reading my article. Have a nice day.

WRITTEN BY Biswaraj Sahoo --AWS Community Builder | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes

Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333