Remove blank lines after code block markers

This commit is contained in:
yeasy
2026-03-21 22:36:09 -07:00
parent 312f8fea42
commit 9ac19d79ee
132 changed files with 0 additions and 1517 deletions

View File

@@ -16,7 +16,6 @@ flowchart LR
Dir1 <-->|Bind Mount| Dir2
```
目录结构同一份文件
```text
/home/user/code/ (或 /usr/share/nginx/html/)
@@ -24,7 +23,6 @@ flowchart LR
├── style.css
└── app.js
```
---
### 8.2.2 Bind Mount vs Volume
@@ -60,7 +58,6 @@ $ docker run -d \
--mount type=bind,source=/宿主机路径,target=/容器路径 \
nginx
```
#### 使用 -v简写
```bash
@@ -68,7 +65,6 @@ $ docker run -d \
-v /宿主机路径:/容器路径 \
nginx
```
#### 两种语法对比
| 特性 | --mount | -v |
@@ -86,7 +82,6 @@ $ docker run -d \
#### 场景一开发环境代码同步
```bash
## 将本地代码目录挂载到容器
$ docker run -d \
@@ -102,40 +97,33 @@ $ echo "Hello" > src/index.html
...
```
#### 场景二配置文件挂载
```bash
## 挂载自定义 nginx 配置
$ docker run -d \
--mount type=bind,source=/path/to/nginx.conf,target=/etc/nginx/nginx.conf,readonly \
nginx
```
#### 场景三日志收集
```bash
## 将容器日志输出到宿主机目录
$ docker run -d \
--mount type=bind,source=/var/log/myapp,target=/app/logs \
myapp
```
#### 场景四共享 SSH 密钥
```bash
## 挂载 SSH 密钥(只读)
$ docker run --rm -it \
--mount type=bind,source=$HOME/.ssh,target=/root/.ssh,readonly \
alpine ssh user@remote
```
---
### 8.2.5 只读挂载
@@ -143,7 +131,6 @@ $ docker run --rm -it \
防止容器修改宿主机文件
```bash
## --mount 语法
$ docker run -d \
@@ -156,20 +143,17 @@ $ docker run -d \
-v /config:/app/config:ro \
myapp
```
容器内尝试写入会报错
```bash
$ touch /app/config/new.txt
touch: /app/config/new.txt: Read-only file system
```
---
### 8.2.6 挂载单个文件
```bash
## 挂载 bash 历史记录
$ docker run --rm -it \
@@ -182,7 +166,6 @@ $ docker run -d \
--mount type=bind,source=/path/to/my.cnf,target=/etc/mysql/my.cnf \
mysql
```
> **注意**挂载单个文件时如果宿主机上的文件被编辑器替换 (而非原地修改)容器内仍是旧文件的 inode建议重启容器或挂载目录
---
@@ -192,7 +175,6 @@ $ docker run -d \
```bash
$ docker inspect mycontainer --format '{{json .Mounts}}' | jq
```
输出
```json
@@ -207,7 +189,6 @@ $ docker inspect mycontainer --format '{{json .Mounts}}' | jq
}
]
```
| 字段 | 说明 |
|------|------|
| `Type` | 挂载类型 (bind)|
@@ -227,7 +208,6 @@ $ docker run --mount type=bind,source=/not/exist,target=/app nginx
docker: Error response from daemon: invalid mount config for type "bind":
bind source path does not exist: /not/exist
```
**解决**确保源路径存在或改用 `-v` (会自动创建)
#### Q权限问题
@@ -235,7 +215,6 @@ bind source path does not exist: /not/exist
容器内用户可能无权访问挂载的文件
```bash
## 方法1确保宿主机文件权限允许容器用户访问
$ chmod -R 755 /path/to/data
@@ -248,18 +227,15 @@ $ docker run -u root ...
$ docker run -u $(id -u):$(id -g) ...
```
#### QmacOS/Windows 性能问题
Docker Desktop Bind Mount 性能较差 (需要跨文件系统同步)
```bash
## 使用 :cached 或 :delegated 提高性能macOS
$ docker run -v /host/path:/container/path:cached myapp
```
| 选项 | 说明 |
|------|------|
| `:cached` | 宿主机权威容器读取可能延迟 |
@@ -273,31 +249,25 @@ $ docker run -v /host/path:/container/path:cached myapp
#### 1. 开发环境使用 Bind Mount
```bash
## 代码热更新
$ docker run -v $(pwd):/app -p 3000:3000 node npm run dev
```
#### 2. 生产环境使用 Volume
```bash
## 数据持久化
$ docker run -v mysql_data:/var/lib/mysql mysql
```
#### 3. 配置文件使用只读挂载
```bash
$ docker run -v /config/nginx.conf:/etc/nginx/nginx.conf:ro nginx
```
#### 4. 注意路径安全
```bash
## ❌ 危险:挂载根目录或敏感目录
$ docker run -v /:/host ...
@@ -306,5 +276,4 @@ $ docker run -v /:/host ...
$ docker run -v /app/data:/data ...
```
---