Docker volumes
You can create a Docker volume using the "docker volume create" command followed by the name of the volume. For example:
docker volume create my_volume
This command creates a volume named "my_volume".
You can list all Docker volumes on your system using the "docker volume ls" command:
docker volume ls
To inspect details about a specific Docker volume, you can use the "docker volume inspect" command followed by the volume name or ID. For example:
docker volume inspect my_volume
You can mount a volume to a container using the "-v" option when running the container with "docker run". For example, to mount the "my_volume" volume to a container:
docker run -d --name my_container -v my_volume:/data nginx
This command runs an NGINX container named "my_container" in detached mode ("-d") and mounts the "my_volume" volume to the "/data" directory within the container.
You can inspect the volumes associated with a specific container using the "docker inspect" command followed by the container name or ID. For example:
docker inspect my_container
This command displays detailed information about the container, including the volumes it's using.
Once a volume is mounted to a container, any data written to the mounted directory inside the container is stored in the volume. You can interact with this data as you would with any other directory on your system.
To remove a Docker volume, you can use the "docker volume rm" command followed by the volume name. For example:
docker volume rm my_volume
Note that you cannot remove a volume that is currently in use by a container. You must first remove any containers that are using the volume or unmount the volume from the container before deleting it.
You've now learned how to create, list, inspect, and manage volumes in Docker containers.