docker_practice/data_management/bind-mounts.md

74 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:/usr/share/nginx/html \
--mount type=bind,source=/src/webapp,target=/usr/share/nginx/html \
nginx:alpine
```
`/src/webapp` `/usr/share/nginx/html`便使 `-v` Docker 使 `--mount` Docker
Docker `读写` `readonly` `只读`
```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
```
`readonly` `只读` `/usr/share/nginx/html`
```bash
/usr/share/nginx/html # 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": "/usr/share/nginx/html",
"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
```