Docker Volume
- Volumes are easy to backup or migrate.
- Volumes can be easily shared with other containers.
- Volumes work on both Linux and windows.
- Volumes can be managed by Docker CLI or Docker API.
- New volumes can have their content pre populated by containers.
- Volumes are better choice than persisting data on container' writable layer.
- Volume's contents exist outside of lifecycle of a given container.
What is tmpfs mount
Limitations on tmpfs mount
- You can share tmpfs mount between containers
- This functionality is only available on Linux.
Let's create tmpfs mount
docker inspect tmptest0
[
{
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
docker run -it -d --name tmptest --tmpfs /app alpine
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"Tmpfs": {
"/app": ""
},
Let's create the volume
docker volume create new-volume
new-volume
docker volume ls
DRIVER VOLUME NAME
local new-volume
docker volume inspect new-volume
[
{
"CreatedAt": "2021-09-22",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/new-volume/_data",
"Name": "new-volume",
"Options": {},
"Scope": "local"
}
]
Start the container with Volume
docker run -d --name voltest -v new-volume:/app alpine
docker container inspect voltest
"HostConfig": {
"Binds": [
"new-volume:/app"
],
Now follow the cleanup with below commands.
docker container stop $(docker ps -q)
docker container rm $(docker ps -aq)
docker volume rm new-volume
No comments:
Post a Comment