Remember the real-time update of the volume mount in the docker container
1. View the container configuration
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"
}
],
The value of Propagation is rprivate, the reason why the folder is not synchronized in real time is because of this, the official document has a form, I post it here
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. |
Let me translate roughly:
Setting type | Description |
---|---|
shared | Any container mounted with this directory will be updated in real time with the host in both directions, and the scope of the current directory, excluding subdirectories |
slave | Any container that mounts this directory will receive real-time updates, and the update is one-way; from the host to the container, the scope of the current directory, excluding subdirectories |
private | Any containers with this directory mounted will not receive real-time updates |
rshared | Same as shared, the scope also includes subdirectories |
rslave | Same as slave, the scope also includes subdirectories |
rprivate | Same as private, the scope also includes subdirectories |
2. Solution
When we develop locally, we want the files to be updated in real time, so we need to set it to rslave.
- When docker starts, you can directly configure it as 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
- You can modify the configuration file docker-compose.yml when using docker-compose up
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 do not use abbreviations, these configurations are fine, after the configuration is complete, look at the container properties
"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"
}
],
In this case, the file is updated in real time, but it is one-way, from the host to the container, what you want to change can be based on your needs.
Make a record of the configuration of this real-time update of the docker folder, hoping to help everyone.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。