📧 chinmayeepavi@gmail.com Support

Volumes and Persistent Data

By default, every file created inside a container lives in that container's writable layer. That data does not persist once the container is removed, and it is awkward to extract if another process needs it. Volumes solve both problems.

docker volume create mydata
docker volume ls
docker volume inspect mydata
docker volume rm mydata
docker volume prune
docker volume --help

# named volume mounted into a container
docker run -d -v mydata:/var/lib/mysql mysql

# bind-mount a host directory
docker run -d -v /host/path:/container/path nginx

# read-only mount
docker run -d -v mydata:/container/path:ro nginx

# reuse another container's volumes
docker run -it --volumes-from ubuntucontainer16 --name ubuntucontainer1604 ubuntu:16.04

The same volume can be mounted into many containers simultaneously — which is how data is shared between them, though concurrent writers need application-level coordination.