Possible way to keep data in container:
- Storing data within the container
- Store your data outside Docker’s Union Filesystem
- Mounting a volume within the Docker host’s filesystem
- Storing data on a network-attached block device. Docker volume plugins allow you to provision and mount shared storage, such as iSCSI, NFS, or FC
Case 1: It 's normal case, you can store any data to guest OS file system. When run container and show your filesystem with 'df' command, show you like this
docker@default:~$ docker@default:~$ docker run -it --name oel-guest1 --rm oraclelinux:7.2 bash [root@acbc5894fa52 /]# [root@acbc5894fa52 /]# [root@acbc5894fa52 /]# df -m Filesystem 1M-blocks Used Available Use% Mounted on none 18306 1808 15532 11% / tmpfs 498 0 498 0% /dev tmpfs 498 0 498 0% /sys/fs/cgroup /dev/sda1 18306 1808 15532 11% /etc/hosts shm 64 0 64 0% /dev/shm [root@acbc5894fa52 /]#
Case 2: Create or run container as volume container. This volume container can share among containers in same Docker host
docker create -v /orahome --name orahome oraclelinux:7.2 /bin/true
docker run -it --volumes-from orahome --name db1 oraclelinux:7.2 bash [root@b5c9355faefb /]# [root@b5c9355faefb /]# df -k Filesystem 1K-blocks Used Available Use% Mounted on none 18745336 1850824 15903788 11% / tmpfs 509888 0 509888 0% /dev tmpfs 509888 0 509888 0% /sys/fs/cgroup /dev/sda1 18745336 1850824 15903788 11% /orahome shm 65536 0 65536 0% /dev/shm exit docker inspect db1 ... "Mounts": [ { "Name": "8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937", "Source": "/mnt/sda1/var/lib/docker/volumes/8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937/_data", "Destination": "/orahome", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" } ], ...
Mount multiple volume
docker create -v /oradata --name oradata oraclelinux:7.2 /bin/true
docker run -it --rm --volumes-from=oradata --volumes-from=orahome --name db1 oraclelinux:7.2 bash
-- add host share folder
docker run -it --rm --privileged -v /cygdrive/d/TEMP:/test --volumes-from=oradata --volumes-from=orahome --name db1 oraclelinux:7.2 bash
docker inspect db1
"Mounts": [ { "Name": "1def11f59155cd3e02bb2b1f94dbe84e0c3b8aff6834e3146da1f21d9ce25c70", "Source": "/mnt/sda1/var/lib/docker/volumes/1def11f59155cd3e02bb2b1f94dbe84e0c3b8aff6834e3146da1f21d9ce25c70/_data", "Destination": "/oradata", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }, { "Name": "8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937", "Source": "/mnt/sda1/var/lib/docker/volumes/8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937/_data", "Destination": "/orahome", "Driver": "local", "Mode": "", "RW": true, "Propagation": "" }, { "Source": "/cygdrive/d/TEMP", "Destination": "/test", "Mode": "", "RW": true, "Propagation": "rprivate" } ],
Case 3: Mounting host file system (Boot2Docker linux)
docker@default:~$ docker run -it --name hostdir --privileged -v /cygdrive/d/TEMP:/test oraclelinux:7.2 bash [root@ea3d6181c614 /]# df -k Filesystem 1K-blocks Used Available Use% Mounted on none 18745336 1355072 16399540 8% / tmpfs 509888 0 509888 0% /dev tmpfs 509888 0 509888 0% /sys/fs/cgroup temp 439887868 211736176 228151692 49% /test /dev/sda1 18745336 1355072 16399540 8% /etc/hosts shm 65536 0 65536 0% /dev/shm [root@ea3d6181c614 /]# exit exit docker@default:~$ docker inspect hostdir
...
"Mounts": [ { "Source": "/cygdrive/d/TEMP", "Destination": "/test", "Mode": "", "RW": true, "Propagation": "rprivate" } ],
...
Case 4: Use Docker volume plugin
..... coming soon .....
No comments:
Post a Comment