只读文件系统
核心概念
# 只读根文件系统
docker run --read-only nginx
# 需要写入的目录用 tmpfs
docker run --read-only --tmpfs /tmp --tmpfs /var/cache/nginx nginx
使用场景
- 防止恶意写入
- 防止容器被篡改
- 提高安全性
Compose 配置
services:
app:
image: my-app
read_only: true
tmpfs:
- /tmp
- /app/cache
小结
| 参数 | 说明 |
|---|---|
--read-only | 只读文件系统 |
--tmpfs | 可写的内存目录 |
| 安全加固 | 防止篡改 |