codegurukool.com · Free coding tutorials & online compiler

Home › Docker Tutorial › Volumes

Volumes

Keep data after a container is removed.

A container's own files vanish when it is removed. A volume is storage managed by Docker that outlives containers. Mount it with -v NAME:PATH. A bind mount (-v ./folder:PATH) shares a folder from your computer instead. The example writes a file from one container and reads it from another.

Example code

docker volume create data
docker run --rm -v data:/d busybox sh -c "echo saved > /d/file.txt"
docker run --rm -v data:/d busybox cat /d/file.txt

Run this code in the online editor

← Layers, caching and multi-stage buildsNetworks →