docker_practice/data_management/bind-mounts.md

76 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#
##
使 `--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
```
`/src/webapp` `/opt/webapp`便使 `-v` Docker 使 `--mount` Docker
Docker `读写` `readonly` `只读`
```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
```
`readonly` `只读` `/opt/webapp`
```bash
/opt/webapp # touch new.txt
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 \
# -v $HOME/.bash_history:/root/.bash_history \
--mount type=bind,source=$HOME/.bash_history,target=/root/.bash_history \
ubuntu:18.04 \
bash
root@2affd44b4667:/# history
1 ls
2 diskutil list
```