1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| root@ruopu:~# docker run -d -P --name web --mount type=bind,source=/etc/init.d,target=/opt/webapp nginx 58ef89a432971bcec8ca0031a69960549d85766b5f42cc40d09e65a662f027c9 # 使用type=bind将本地的目录挂载到容器中,但用source指定的本地目录一定要使用绝对路径,如果本地目录不存在,Docker会报错。
* 以只读方式挂载本地目录 root@ruopu:~# docker run -d -P --name web1 --mount type=bind,source=/etc/init.d,target=/opt/webapp,readonly nginx f59500a342675873413040fa09dea6f626df2215430640830fde9e46c1195fc5 # 创建时加入readonly,使用户对目录只有只读权限 root@10c115755312:/# cd /opt/webapp/ root@10c115755312:/opt/webapp# mkdir a mkdir: cannot create directory 'a': Read-only file system # 创建目录时会有不能创建的提示 root@ruopu:~# docker inspect web1|grep Mounts -A 10 "Mounts": [ { "Type": "bind", "Source": "/etc/init.d", "Target": "/opt/webapp", "ReadOnly": true } ], "Mounts": [ { "Type": "bind", "Source": "/etc/init.d", "Destination": "/opt/webapp", "Mode": "", "RW": false, "Propagation": "rprivate" } ], # 可以看到,上面的ReadOnly是true,下面的RW是false
|