docker_practice/data_management/bind-mounts.md

76 lines
2.1 KiB
Go
Raw Normal View History

#
2017-11-22 16:19:30 +00:00
##
2017-11-22 16:19:30 +00: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 02:26:48 +00:00
`/src/webapp` `/opt/webapp`便使 `-v` Docker 使 `--mount` Docker
2017-11-22 16:19:30 +00:00
2017-11-24 04:30:18 +00:00
Docker `读写` `readonly` `只读`
2017-11-22 16:19:30 +00: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 08:12:28 +00:00
`readonly` `只读` `/opt/webapp`
2017-11-22 16:19:30 +00:00
```bash
2017-12-26 08:05:26 +00:00
/opt/webapp # touch new.txt
2017-11-22 16:19:30 +00:00
touch: new.txt: Read-only file system
```
##
2017-11-22 16:19:30 +00:00
使 `web`
```bash
$ docker inspect web
```
`挂载主机目录` "Mounts" Key
```json
"Mounts": [
{
"Type": "bind",
"Source": "/src/webapp",
"Destination": "/opt/webapp",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
```
##
2017-11-22 16:19:30 +00:00
`--mount`
```bash
$ docker run --rm -it \
2017-11-24 04:30:18 +00: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 04:30:18 +00:00
bash
root@2affd44b4667:/# history
1 ls
2 diskutil list
2017-11-22 16:19:30 +00:00
```