April 2018
Beginner
398 pages
10h 11m
English
Once we have created a named volume, we can mount it into a container. For this, we can use the -v parameter in the docker container run command:
$ docker container run --name test -it \ -v my-data:/data alpine /bin/sh
The preceding command mounts the my-data volume to the /data folder inside the container. Inside the container, we can now create files in the /data folder and then exit:
# / cd /data # / echo "Some data" > data.txt # / echo "Some more data" > data2.txt # / exit
If we navigate to the host folder that contains the volume data and list its content, we should see the two files we just created inside the container:
$ cd /mnt/sda1/var/lib/docker/volumes/my-data/_data $ ls -l total 8 -rw-r--r-- 1 root root 10 ...
Read now
Unlock full access