Use bind mounts

Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its full or relative path on the host machine. By contrast, when you use a volume, a new directory is created within Docker’s storage directory on the host machine, and Docker manages that directory’s contents.

Start a container with a bind mount

Consider a case where you have a directory source and that when you build the source code, the artifacts are saved into another directory source/target/. You want the artifacts to be available to the container at /app/, and you want the container to get access to a new build each time you build the source on your development host. Use the following command to bind-mount the target/ directory into your container at /app/. Run the command from within the source directory. The $(pwd) sub-command expands to the current working directory on Linux or macOS hosts.

The --mount and -v examples below produce the same result. You can’t run them both unless you remove the devtest container after running the first one.

--mount 语法格式:

$ docker run -d \
-it \
--name devtest \
--mount type=bind,source="$(pwd)"/target,target=/app \
nginx:latest

-v 语法格式:

$ docker run -d \
-it \
--name devtest \
-v "$(pwd)"/target:/app \
nginx:latest

Mounting into a non-empty directory on the container

If you bind-mount into a non-empty directory on the container, the directory’s existing contents are obscured(覆盖) by the bind mount. This can be beneficial, such as when you want to test a new version of your application without building a new image. However, it can also be surprising and this behavior differs from that of docker volumes.

Docker 数据管理-bind mount的更多相关文章

  1. [转帖]Docker的数据管理(volume/bind mount/tmpfs)

    Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs) https://www.cnblogs.com/zhuochong/p/10069719.html do ...

  2. Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs)

    Docker提供了三种不同的方式用于将宿主的数据挂载到容器中:volumes,bind mounts,tmpfs volumes.当你不知道该选择哪种方式时,记住,volumes总是正确的选择. vo ...

  3. Docker的数据管理(volume/bind mount/tmpfs)

    Docker提供了三种不同的方式用于将宿主的数据挂载到容器中:volumes,bind mounts,tmpfs volumes.当你不知道该选择哪种方式时,记住,volumes总是正确的选择. vo ...

  4. Data Volume 之 bind mount - 每天5分钟玩转 Docker 容器技术(39)

    storage driver 和 data volume 是容器存放数据的两种方式,上一节我们学习了 storage driver,本节开始讨论 Data Volume. Data Volume 本质 ...

  5. Docker 数据管理-三种数据mount方式

    可以在Container可写层存储数据,但是有三个缺点: 当Container销毁时,数据不能持久保存. Container的可写层和Container所在的主机紧耦合,不容易将数据移动到其他地方. ...

  6. docker的volume和bind mount究竟有什么区别?

    不知道你在使用docker的时候,有没有注意到volume mount和bind mount的使用? 进一步说,他们之间的区别到底是什么? 接下来的内容,我们就为你揭开他们的神秘面纱. 相同之处 首先 ...

  7. <Docker学习>5. docker数据管理

    当我们创建了一个tomcat容器,如何简单部署一个web应用?如何将war包放入到容器中?也就是说怎么样把文件从宿主机中 "放入" 到容器中? docker cp命令可以将宿主机本 ...

  8. 039、Data Volume 之 bind mount (2019-02-28 周四)

    参考https://www.cnblogs.com/CloudMan6/p/7142150.html     Date Volume 本质上是Dokcer host文件系统中的目录或者文件,能够直接被 ...

  9. Docker Swarm bind 数据持久化

    Docker Swarm bind 数据持久化 bind:主要将工作节点宿主级文件或目录,同步挂载到容器中. 环境: 系统:Centos 7.4 x64 应用版本:Docker 18.09.0 管理节 ...

随机推荐

  1. ftp uploadFileAction(重要)

    TelnetOUtputStream os = ftpClient.put(filename); File file_in = new File(localPath); FileInputStream ...

  2. hdu 3715(二分+2-sat)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3715 思路:二分深度,2-sat判断可行性,根据矛盾关系建图:设a=0,a'=1,b=0,b'=1;如 ...

  3. gcc 编译 连接 生成可执行文件

    gcc c语言编译器 g++ c++编译器 gcc a.c  生成默认的a.out 可执行文件  ./a.out  来执行 gcc -c a.c 编译生成 a.o 目标文件 可以检查语法错误 gcc ...

  4. [CTSC1999][网络流24题] 星际转移

    36. [CTSC1999][网络流24题] 星际转移 ★★★☆   输入文件:home.in   输出文件:home.out   简单对比时间限制:1 s   内存限制:128 MB «问题描述: ...

  5. POJ2417 Discrete Logging【BSGS】

    Discrete Logging Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5577   Accepted: 2494 ...

  6. proguard-project.txt和project.properties混淆代码

     [转]利用android proguard混淆代码 防止反编译,优化代码 网上虽然有很多相关博客,不过貌似都不是最新版的..于是百度+谷歌+github上的开源demo,终于成功的配置了androi ...

  7. influxDB---Data Exploration

    the group clause group by 返回的分组结果是根据用户指定的tag ,time interval. 1.group by tags 2.group by time interva ...

  8. TFS二次开发-基线文件管理器(2)-TFS登录

    首先需要做一个TFS的登录. 以前的文章是使用的DomainProjectPicker 最新的VS里面使用的是TeamProjectPicker 首先可以在WinForm程序上写一个Button,然后 ...

  9. python系列九:python3迭代器和生成器

    #!/usr/bin/python import sys '''迭代器是一个可以记住遍历的位置的对象.迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后退.迭代器有 ...

  10. .Net自带ChartControl报错:Auto interval does not have proper value

    出现这个错误的原因是我们给ChartControl同时设置了Minimum和Maxmum的值,而这两个值又恰好相等. chart.ChartAreas[0].AxisY.Minimum=min; ch ...