39 lines
1.3 KiB
Markdown
39 lines
1.3 KiB
Markdown
---
|
||
title: "Docker 用户组"
|
||
tags: [docker, security, permissions]
|
||
date: 2026-04-22
|
||
---
|
||
|
||
# Docker 用户组
|
||
|
||
## Definition
|
||
Docker 用户组是 Linux 系统中的用户组机制,允许组成员无需 `sudo` 前缀直接运行 Docker 命令。
|
||
|
||
## Configuration
|
||
```bash
|
||
# 将用户添加到 docker 用户组
|
||
sudo usermod -aG docker $USER
|
||
|
||
# 刷新组成员资格(需重新登录或重启终端)
|
||
newgrp docker
|
||
# 或直接登出再登入
|
||
```
|
||
|
||
## Security Implications
|
||
⚠️ **安全警告**:docker 用户组成员拥有与 root 用户等效的权限,因为 Docker 容器默认以 root 身份运行。攻击者如果能访问 docker 用户组的成员账户,可能通过容器逃逸获得宿主机 root 权限。
|
||
|
||
## Best Practices
|
||
1. 仅将受信任的用户添加到 docker 用户组
|
||
2. 优先使用非 root 用户运行容器(`PUID/PGID` 环境变量)
|
||
3. 定期审查 docker 用户组成员
|
||
4. 考虑使用 Podman 作为替代方案(支持无 root 模式)
|
||
|
||
## Related Sources
|
||
- [[如何在ubuntu-server安装-docker-docker-compose]] — docker 用户组配置步骤
|
||
|
||
## Related Concepts
|
||
- [[Docker Engine]] — 被无 sudo 访问的组件
|
||
- [[用户权限]] — Linux 用户组机制
|
||
- [[容器资源限制]] — 配合非 root 用户的安全实践
|
||
- [[PUID/PGID]] — Docker 容器的非 root 用户映射
|