Docker绑定安装用法 [英] Docker bind mount usage

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

问题描述

我们的应用程序在unix盒(例如box1)上运行,在该盒上将一个nfs文件管理器安装在/var/app/data 目录中.

Our application is running on a unix box(let's say box1) on which one nfs filer is mounted on /var/app/data directory.

应用程序在已安装的目录/var/app/data 上写入一些文本文件.

Application writes some text file on the mounted directory /var/app/data.

我们的下游应用程序(在某些其他Unix框上运行)将读取nfs filer中存在的这些文件.我们正计划将我们的应用程序迁移到docker.

Our downstream application (running on some other unix box) will read these files as they are present on nfs filer. We are planning to migrate our application to docker.

我正在考虑使用绑定安装功能,因为它将允许我将主机(box1)目录/var/app/data 映射到容器中的任何目录.

I am thinking to use bind-mount feature as it will allow me to map host machine(box1) directory /var/app/data to any directory in container.

但是,我发现大多数博客都建议使用卷而不是绑定卷.有人可以据我所知如何在我的场景中使用卷挂载,在创建卷时我们不能提及源目录(在我的情况下为/var/app/data ).

However I have found most blogs suggesting to use volumes over bind-mount. can someone please how to use volume mount in my scenario as upto my understanding, we can not mention source directory (/var/app/data in my case) while creating the volume.

推荐答案

查看

  • 创建docker卷: docker卷create my_vol
  • 安装容器中的卷: docker run -d -v my_vol:/destination_with_content -n my_container busybox
  • 使用所需的数据填充它: docker cp/var/app/data my_container:/destination_with_content
  • 现在您可以运行所需的容器并传递填充的卷: docker run -d -v my_vol:/destination_new_container my_image
  • 这篇关于Docker绑定安装用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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