Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save binarytemple-clients/554e1a50e5a12c25cf5f to your computer and use it in GitHub Desktop.
Save binarytemple-clients/554e1a50e5a12c25cf5f to your computer and use it in GitHub Desktop.
setting up docker volumes

docker volume ls

docker volume create --name mysql-data 
mysql-data

Create a file inside a volume, the container is terminated. The container is restarted, and the file is still there

[bryan@localhost ~]$ docker run -ti  -v mysql-data:/world ubuntu /bin/bash
root@6abd8791aab9:/# echo 'hello world' > /world/hello 
root@6abd8791aab9:/# exit
exit
[bryan@localhost ~]$ docker run -ti  -v mysql-data:/world ubuntu /bin/bash
root@d983bc65caf3:/# cat /world/hello 
hello world

List the existing volumes

[bryan@localhost ~]$ docker volume ls
DRIVER              VOLUME NAME
local               e7fc0912ec54ae4fa1a8ce30126b851810de67d912c7b949fdf1d38a5396a176
local               0fa6006aeeb06914b03f84b12645e95c0d3ba64ce2a1020ed28cee2a2e40f464
local               b3996e0b823234388327acb66ad20a61aed7e00e2c4a3918a80f9a60fd5a4021
local               mysql-data
local               3b1376c511889839cafde3fdff5263191438fa5fbd33fd1d8de50d1f07c26819

Inspect the mysql-data volume:

[bryan@localhost ~]$ docker volume inspect mysql-data 
[
    {
        "Name": "mysql-data",
        "Driver": "local",
        "Mountpoint": "/var/lib/docker/volumes/mysql-data/_data"
    }
]

Inspect the local disk copy

[bryan@localhost ~]$ sudo ls -la /var/lib/docker/volumes/mysql-data/_data
total 4
drwxr-xr-x. 2 root root 18 Mar  6 19:28 .
drwxr-xr-x. 3 root root 18 Mar  6 19:25 ..
-rw-r--r--. 1 root root 12 Mar  6 19:31 hello

Backing up volumes:

https://docs.docker.com/engine/userguide/containers/dockervolumes/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment