02 Jan 2024
By default all the changes inside the container are lost when the container stops. If we want to keep data between runs, Docker volumes and bind mounts can help.
→ A docker container runs software stack defined in an image.
→ Can be shared between containers.
docker volume ls
shows all the volumes known to Dockerdocker volume ls -f name=data
allows us to filter volumesdocker volume rm data_vol
removes the volumedocker volume prune
removes all unused volumes→ A connection from the container to a directory on the host machine. It allows the host to share it’s own file system with the container.
A bind mount uses the host file system, but Docker volumes are native to Docker. The volume has a lifecycle that’s longer than the container’s, allowing it to persist until no longer needed. Volumes can be shared between containers.
docker volume
allows you to manage volumes. For example:
$ docker volume ls
DRIVER VOLUME NAME
local data_volume
To remove volume:
$ docker volume rm data_volume
To remove all unused volumes:
$ docker volume prune