记docker容器内volume|记docker容器内volume mount实时更新
记docker 容器内 volume mount 实时更新
一.查看容器配置
docker inspect [container id or name]
"Mounts": [
{
"Type": "bind",
"Source": "D:\\workspace\\dracohub",
"Destination": "/app",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "D:\\workspace\\dracohub\\deploy\\php.ini",
"Destination": "/opt/bitnami/php/conf/php.ini",
"Mode": "",
"RW": false,
"Propagation": "rprivate"
}
],
Propagation 的值为 rprivate , 文件夹不实时同步的原因就是因为这个,官方文档有个表格,我贴在这里
Propagation setting | Description |
---|---|
shared |
Sub-mounts of the original mount are exposed to replica mounts, and sub-mounts of replica mounts are also propagated to the original mount. |
slave |
similar to a shared mount, but only in one direction. If the original mount exposes a sub-mount, the replica mount can see it. However, if the replica mount exposes a sub-mount, the original mount cannot see it. |
private |
The mount is private. Sub-mounts within it are not exposed to replica mounts, and sub-mounts of replica mounts are not exposed to the original mount. |
rshared |
The same as shared, but the propagation also extends to and from mount points nested within any of the original or replica mount points. |
rslave |
The same as slave, but the propagation also extends to and from mount points nested within any of the original or replica mount points. |
rprivate |
The default. The same as private, meaning that no mount points anywhere within the original or replica mount points propagate in either direction. |
设置类型 | Description |
---|---|
shared |
任何挂载了此目录的容器都会双向和宿主机实时更新,作用范围当前目录,不包括子目录 |
slave |
任何挂载了此目录的容器都会收到实时更新,更新是单向的; 宿主机到容器,作用范围当前目录,不包括子目录 |
private |
任何挂载了此目录的容器都不会收到实时更新 |
rshared |
同 shared, 作用范围也包括子目录 |
rslave |
同 slave, 作用范围也包括子目录 |
rprivate |
同 private, 作用范围也包括子目录 |
- docker 启动时可以直接命令配置为 rslave
docker run -d \
-it \
--name devtest \
--mount type=bind,source="$(pwd)"/target,target=/app \
--mount type=bind,source="$(pwd)"/target,target=/app2,readonly,bind-propagation=rslave \
nginx:latest
- 使用 docker-compose up 时可以修改配置文件 docker-compose.yml
volumes:
- type: bind
source: ./
target: /app
read_only: false
bind:
propagation: rslave
- type: bind
source: ./deploy/php.ini
target: /opt/bitnami/php/conf/php.ini
read_only: true
bind:
propagation: rslave
volumes 不使用简写,这些配置就可以, 配置好了再看一下容器属性
"Mounts": [
{
"Type": "bind",
"Source": "D:\\workspace\\dracohub",
"Destination": "/app",
"Mode": "",
"RW": true,
"Propagation": "rslave"
},
{
"Type": "bind",
"Source": "D:\\workspace\\dracohub\\deploy\\php.ini",
"Destination": "/opt/bitnami/php/conf/php.ini",
"Mode": "",
"RW": false,
"Propagation": "rslave"
}
],
这样的话文件就是实时更新的,但是是单向的,是从宿主机到容器,想改成什么可以根据自己需求.
【记docker容器内volume|记docker容器内volume mount实时更新】对这次的docker 文件夹实时更新的配置做个记录,希望能帮到大家.
推荐阅读
- Docker应用:容器间通信与Mariadb数据库主从复制
- EffectiveObjective-C2.0|EffectiveObjective-C2.0 笔记 - 第二部分
- 野营记-第五章|野营记-第五章 讨伐梦魇兽
- 20170612时间和注意力开销记录
- 2018年11月19日|2018年11月19日 星期一 亲子日记第144篇
- 叙述作文
- 2019年12月24日
- 人生感悟记#环境仪器宋庆国成长记#072
- 2019.4.18感恩日记
- 四首关于旅行记忆的外文歌曲