Docker Data Management
There are two methods to handle Docker data.
Method 1 : Data Volume
1 | $ docker run -v /local/path:/docker/path shaoguangleo/ubuntu:lateset |
Also , you can mount several directories at the same time.
1 | $ docker run -v /local/path:/docker/path -v /local/path2:/docker/path2 -v /local/path3:/docker/path3 shaoguangleo/ubuntu:lateset |
By default the data volume can be read and write, you can specify the parameter point out.
For example: Just read
1 | $ docker run -v /local/path:/docker/path:ro shaoguangleo/ubuntu:lateset |
Method 2 : Data Volume Container
First create a data volume container and mount to /dbdata
1 | $ docker run -it -v /dbdata shaoguangleo/ubuntu:lateset |
Then we can using --volumes-from
to mount the dbdata through many dockers.
1 | $ docker run -it --volumes-from dbdata --name db1 ubuntu |
So we can modify some file in dbdata which can immediately work in other dockers.
Docker backup/restore data
By the way, we can also using docker to backup or restore data.
backup
1 | $ docker run --volumes-from dbdata -v $(pwd):/backup --name worker ubuntu tar cvf /backup/backup.tar /dbdata |
restore
1 | $ docker run -v /dbdata --name dbdata2 ubuntu /bin/bash |