码头安装在主机上的卷 [英] docker mounting volumes on host

查看:146
本文介绍了码头安装在主机上的卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功地能够使用

docker run -v /host/path:/container/path ...

但是我的问题是这个和使用 VOLUME 在Dockerfile中的命令

But my question is what the difference between this and using the VOLUME command in the Dockerfile

VOLUME /path

我使用的图像有一个 VOLUME 命令,我想知道如何与我的主机分享。我已经使用上面的 -v 命令完成了,但是我不知道我是否需要 -v VOLUME

I am using an image that has a VOLUME command, and I'd like to know how to share it with my host. I have done it using the -v command above, but I didn't know if I needed both the -v and VOLUME.

推荐答案

VOLUME 命令将在容器内装载一个目录,并将容器文件结构之外的主机磁盘上的目录中创建或编辑的任何文件存储在绕过联合文件系统的位置。

The VOLUME command will mount a directory inside your container and store any files created or edited inside that directory on your hosts disk outside the container file structure, bypassing the union file system.

这个想法是,您的数据库可以在您的Docker容器之间共享,只要有一个引用它们的容器(运行或停止),它们就会保持在周围。

The idea is that your volumes can be shared between your docker containers and they will stay around as long as there's a container (running or stopped) that references them.

当您运行时,您可以使用 - volumes从命令,使其他容器装载现有卷(在容器之间有效共享)一个容器。

You can have other containers mount existing volumes (effectively sharing them between containers) by using the --volumes-from command when you run a container.

VOLUME -v 是这样的: -v 将从您的Dock中的操作系统挂载现有文件呃容器和 VOLUME 将在您的主机上创建一个新的空卷,并将其装载到容器中。

The fundamental difference between VOLUME and -v is this: -v will mount existing files from your operating system inside your docker container and VOLUME will create a new, empty volume on your host and mount it inside your container.

示例:


  1. 您有一个Dockerfile定义了一个 VOLUME / var / lib / mysql

  2. 您构建停泊点图片并将其标记为 some-volume

  3. 您运行容器

然后,


  1. 您要使用此卷的另一个码头服务器映像

  2. 您使用以下命令运行docker容器:
    docker run --volumes-from some-volume docker-image-name:tag

  3. 现在你有一个运行的docker容器,它的卷从 some-volume 载入 / var / lib / mysql

  1. You have another docker image that you want to use this volume
  2. You run the docker container with the following: docker run --volumes-from some-volume docker-image-name:tag
  3. Now you have a docker container running that will have the volume from some-volume mounted in /var/lib/mysql

注意:使用 - 卷从将会将卷挂载到卷的位置上的任何内容。即,如果你在 / var / lib / mysql 中有东西,它将被卷的内容所替代。

Note: Using --volumes-from will mount the volume over whatever exists in the location of the volume. I.e., if you had stuff in /var/lib/mysql, it will be replaced with the contents of the volume.

这篇关于码头安装在主机上的卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆