0%

Docker Data Management

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
2
3
$ docker run -it --volumes-from dbdata --name db1 ubuntu
$ docker run -it --volumes-from dbdata --name db2 ubuntu
$ docker run -it --volumes-from dbdata --name db3 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
2
$ docker run -v /dbdata --name dbdata2 ubuntu /bin/bash
$ docker run --volumes-from dbdata2 -v $(pwd):/backup busybox tar xvf /backup/backup.tar
处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道