快速判断
Docker容器与镜像、Compose编排、网络与数据卷、调试与生产环境加固,以及保障真实环境稳定的各项命令。
适合任务
- 按 SkillHub 收录说明复用成熟任务流程。
- 通过下载包离线阅读完整 Skill 内容。
- 结合热度指标优先评估常用 Skill。
输入与输出
输入:任务目标、上下文材料、文件路径、约束条件或需要处理的内容。
输出:按 Skill 说明生成的文档、代码、检查结果、计划、建议或操作步骤。
示例任务
- 使用 Docker 帮我处理当前任务,并说明需要准备哪些输入。
- 根据 Docker 的说明,先列出使用前的安全检查项。
安装方式
- 下载本站提供的 Skill ZIP 并解压。
- 把解压后的 Skill 目录放入当前 AI 工具支持的
skills目录。 - 如需在线查看原始内容,可打开 GitHub 的
SKILL.md。
在线原始地址:skillhub-docker/SKILL.md
风险边界
SkillHub 提供了源站安全报告入口,但本站不替代人工审查。使用前仍需检查权限、外部依赖和敏感数据边界。
SKILL.md 文档介绍
When to Use
Use when the task involves Docker, Dockerfiles, container builds, Compose, image publishing, networking, volumes, logs, debugging, or production container operations. This skill is stateless and should be applied directly whenever Docker work appears.
Quick Reference
| Topic | File |
|-------|------|
| Essential commands | commands.md |
| Dockerfile patterns | images.md |
| Compose orchestration | compose.md |
| Networking & volumes | infrastructure.md |
| Security hardening | security.md |
Core Rules
1. Pin Image Versions
python:3.11.5-slimnotpython:latest- Today's latest differs from tomorrow's — breaks immutable builds
2. Combine RUN Commands
apt-get update && apt-get install -y pkgin ONE layer- Separate layers = stale package cache weeks later
3. Non-Root by Default
- Add
USER nonrootin Dockerfile - Running as root fails security scans and platform policies
4. Set Resource Limits
-m 512mon every container- OOM killer strikes without warning otherwise
5. Configure Log Rotation
- Default json-file driver has no size limit
- One chatty container fills disk and crashes host
Image Traps
- Multi-stage builds: forgotten
--from=buildercopies from wrong stage silently - COPY before RUN invalidates cache on every file change — copy requirements first, install, then copy code
ADDextracts archives automatically — useCOPYunless you need extraction- Build args visible in image history — never use for secrets
Runtime Traps
localhostinside container is container's localhost — bind to0.0.0.0- Port already in use: previous container still stopping — wait or force remove
- Exit code 137 = OOM killed, 139 = segfault — check with
docker inspect --format='{{.State.ExitCode}}' - No shell in distroless images —
docker cpfiles out or use debug sidecar
Networking Traps
- Container DNS only works on custom networks — default bridge can't resolve names
- Published ports bind to
0.0.0.0— use127.0.0.1:5432:5432for local-only - Zombie connections from killed containers — set health checks and restart policies
Compose Traps
depends_onwaits for container start, not service ready — usecondition: service_healthy.envfile in wrong directory silently ignored — must be next to docker-compose.yml- Volume mounts overwrite container files — empty host dir = empty container dir
- YAML anchors don't work across files — use multiple compose files instead
Volume Traps
- Anonymous volumes accumulate silently — use named volumes
- Bind mounts have permission issues — container user must match host user
docker system prunedoesn't remove named volumes — add--volumesflag- Stopped container data persists until container removed
Resource Leaks
- Dangling images grow unbounded —
docker image pruneregularly - Build cache grows forever —
docker builder prunereclaims space - Stopped containers consume disk —
docker container pruneor--rmon run - Networks pile up from compose projects —
docker network prune
Secrets and Security
- ENV and COPY bake secrets into layer history permanently — use secrets mount or runtime env
--privilegeddisables all security — almost never needed, find specific capability instead- Images from unknown registries may be malicious — verify sources
- Build args visible in image history — don't use for secrets
Debugging
- Exit code 137 = OOM killed, 139 = segfault — check
docker inspect --format='{{.State.ExitCode}}' - Container won't start: check logs even for failed containers —
docker logs <container> - No shell in distroless images —
docker cpfiles out or use debug sidecar - Inspect filesystem of dead container —
docker cp deadcontainer:/path ./local
Related Skills
Install with clawhub install <slug> if user confirms:
devops— deployment pipelineslinux— host system managementserver— server administration
Feedback
- If useful:
clawhub star docker - Stay updated:
clawhub sync