table of Contents
Article Directory
Container storage
Data volume management
Core options:
- -v host directory: specify the directory mounted to the container.
To map multiple host directories, just write a few more -v.
Create volume when mounting
- Mount the volume:
docker run -d -p 80:80 -v /data:/usr/share/nginx/html nginx:latest
- Set up a shared volume and start a new container with the same volume:
docker run -d -p 8080:80 -v /data:/usr/share/nginx/html nginx:latest
Mount after creating the volume
- View the list of volumes:
docker volume ls
- View data disks not used by the container
docker volume ls -f dangling=true
- Create a volume:
$ docker volume create
f3b95f7bd17da220e63d4e70850b8d7fb3e20f8ad02043423a39fdd072b83521
$ docker volume ls
DRIVER VOLUME NAME
local f3b95f7bd17da220e63d4e70850b8d7fb3e20f8ad02043423a39fdd072b83521
- View volume path:
$ docker volume inspect <volume_name>
[
{
"CreatedAt": "2018-02-01T00:39:25+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/clsn/_data",
"Name": "clsn",
"Options": {},
"Scope": "local"
}
]
- Use the volume to create a container:
docker run -d -p 9000:80 -v <volume_name>:/usr/share/nginx/html nginx:latest
- Delete volume
docker rm -v <volume_name>
Data container management
A special container can be created to act as a data container, that is, when the container is created, the data disk of this container is specified, and then other containers can use this data container as their data disk.
- Create a data container:
docker create -v /mnt -it --name newnginx docker.io/nginx /bin/bash
- Use this data container to run a container
docker run --volumes-from newnginx --name nginx1 -it docker.io/nginx /bin/bash