docker_practice/data_management/bind-mounts.md

76 lines
2.1 KiB
Go
Raw Normal View History

2017-11-23 00:19:30 +08:00
##
###
使 `--mount`
```bash
$ docker run -d -P \
--name web \
# -v /src/webapp:/opt/webapp \
--mount type=bind,source=/src/webapp,target=/opt/webapp \
training/webapp \
python app.py
```
2017-12-03 10:26:48 +08:00
`/src/webapp` `/opt/webapp`便使 `-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:/opt/webapp:ro \
--mount type=bind,source=/src/webapp,target=/opt/webapp,readonly \
training/webapp \
python app.py
```
2017-12-26 16:12:28 +08:00
`readonly` `只读` `/opt/webapp`
2017-11-23 00:19:30 +08:00
```bash
2017-12-26 16:05:26 +08:00
/opt/webapp # touch new.txt
2017-11-23 00:19:30 +08:00
touch: new.txt: Read-only file system
```
###
使 `web`
```bash
$ docker inspect web
```
`挂载主机目录` "Mounts" Key
```json
"Mounts": [
{
"Type": "bind",
"Source": "/src/webapp",
"Destination": "/opt/webapp",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
```
###
`--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
```