docker_practice/data_management/bind-mounts.md

74 lines
2.1 KiB
Go
Raw Normal View History

#
2017-11-23 00:19:30 +08:00
##
2017-11-23 00:19:30 +08:00
使 `--mount`
```bash
$ docker run -d -P \
--name web \
# -v /src/webapp:/usr/share/nginx/html \
--mount type=bind,source=/src/webapp,target=/usr/share/nginx/html \
nginx:alpine
2017-11-23 00:19:30 +08:00
```
`/src/webapp` `/usr/share/nginx/html`便使 `-v` Docker 使 `--mount` Docker
2017-11-23 00:19:30 +08:00
2017-11-24 12:30:18 +08:00
Docker `读写` `readonly` `只读`
2017-11-23 00:19:30 +08:00
```bash
$ docker run -d -P \
--name web \
# -v /src/webapp:/usr/share/nginx/html:ro \
--mount type=bind,source=/src/webapp,target=/usr/share/nginx/html,readonly \
nginx:alpine
2017-11-23 00:19:30 +08:00
```
`readonly` `只读` `/usr/share/nginx/html`
2017-11-23 00:19:30 +08:00
```bash
/usr/share/nginx/html # touch new.txt
2017-11-23 00:19:30 +08:00
touch: new.txt: Read-only file system
```
##
2017-11-23 00:19:30 +08:00
使 `web`
```bash
$ docker inspect web
```
`挂载主机目录` "Mounts" Key
```json
"Mounts": [
{
"Type": "bind",
"Source": "/src/webapp",
"Destination": "/usr/share/nginx/html",
2017-11-23 00:19:30 +08:00
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
```
##
2017-11-23 00:19:30 +08:00
`--mount`
```bash
$ docker run --rm -it \
2017-11-24 12:30:18 +08:00
# -v $HOME/.bash_history:/root/.bash_history \
--mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history \
ubuntu:18.04 \
2017-11-24 12:30:18 +08:00
bash
root@2affd44b4667:/# history
1 ls
2 diskutil list
2017-11-23 00:19:30 +08:00
```