Docker数据存储和volume

假如你在container中产生了一些数据,默认情况下是保存在container layer中的,随着container的删除而删除

但有时候,你需要把数据保存在container外的宿主机中,方便container外的程序使用

Docker有四种方式支持数据写出:

  • volumes。大多数情况使用本方案。在宿主机的本地文件系统,有docker专属的路径,在其中创建一个目录,然后把该目录挂载到container中,container在该目录下写入的内容,都保存在宿主机中,不随container删除而消失。该路径只能由docker访问,默认在/var/lib/docker/volumes目录。
  • bind mounts。这个和volumes类似,特殊之处在于,volumes只能在docker特定的目录下操作,而bind mount可以把宿主机的任意路径挂载到container中,container内的容器修改宿主机的内容后,也会永久反映在宿主机中。这种方式的自由度更大,也更有风险。
  • tmpfs mount。仅限Linux环境,数据保存在宿主机的内存中,并不持久化
  • named pipe。仅限windows环境

具体的差别如下图:

volume driver

使用volumes方式的时候,可以把云路径创建为volume,提供了保存文件到远程主机的可能

该技术需要指定volume driver。volume driver即各云volume技术的具体实现,docker通过统一的接口,可自由配置需要的volume driver

比如以下使用了一个vieux/sshfs volume driver,这个driver通过ssh方式,可以把远程主机的目录创建为volume:

# 安装volume driver
$ docker plugin install --grant-all-permissions vieux/sshfs

#把远程主机的/home/test目录创建为volume
docker volume create --driver vieux/sshfs \
  -o sshcmd=test@node2:/home/test \
  -o password=testpassword \
  sshvolume

其他还有NFS的volume driver, 或者亚马逊S3的volume driver等

Ref



《 “Docker数据存储和volume” 》 有 3 条评论

  1. Her eyes narrowed common blood pressure medications during pregnancy slightly, and a gleam of cold light flashed past, Froya smiled sadly and said, And I still think about fighting for such a father and brother, and even separate them from you misoprostol over the counter cvs

  2. I feel like I am going to throw up all the time and my back is so I also have cramps like knife staying cramps in my lower abdomen my sinus are so weird like for one moment I can t smell anything and the next I smell acid priligy walgreens

  3. Dr Toth for example would be likely to recommend very aggressive treatment preconception and continuing periodically throughout pregnancy buy priligy online European Institute of Oncology, Via Ripamonti, I 20141, Milan, Italy

回复 cytotec pills buy 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

About Me

一位程序员,会弹吉他,喜欢读诗。
有一颗感恩的心,一位美丽的妻子,两个可爱的女儿
mail: geraldlee0825@gmail.com
github: https://github.com/lisuxiaoqi
medium: https://medium.com/@geraldlee0825