
docker-run
Guidance for running and managing Docker containers. Covers the complete container lifecycle (create/start/stop/rm/restart), resource constraints (--memory/--cpus), health checks (HEALTHCHECK), restart policies, logging drivers, container inspection (inspect/stats/top), exec debugging, and signal handling. Use when the user asks about docker run, container management, resource limits, health checks, docker logs, docker exec, restart policies, or needs to manage running containers. 使用场景:docker run、容器管理、资源限制、健康检查、重启策略、docker logs、docker exec、docker ps.
- Installs
- 100
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-run- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads docker-run automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Docker Run — Container Lifecycle Management
Complete guidance for running, monitoring, and managing Docker containers.
When to Use
ALWAYS use this skill when the user mentions:
- "docker run", "运行容器", "启动容器"
- "docker ps", "docker stop", "docker restart"
- "容器资源限制", "memory limit", "CPU limit"
- "健康检查", "healthcheck"
- "docker logs", "查看日志"
- "docker exec", "进入容器"
- "restart policy", "容器重启策略"
Container Lifecycle
docker pull → docker create → docker start → docker run (create+start)
│
┌─────────────────────┼─────────────────────┐
▼ ▼ ▼
Running Paused/Stopped Killed
│ │
▼ ▼
docker stop docker start
docker kill docker restart
docker rm docker rm -f
docker run — Complete Reference
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
# Most common form
docker run -d --name myapp \
-p 8080:8080 \
-v /host/path:/container/path \
-e ENV_VAR=value \
--restart unless-stopped \
myimage:tag
| Flag | Purpose | Example |
|---|---|---|
-d | Detached (background) | -d |
--name | Container name | --name my-nginx |
-p | Port mapping (host:container) | -p 8080:80 |
-v | Volume/bind mount | -v data:/var/lib/mysql |
-e | Environment variable | -e DB_HOST=localhost |
--env-file | Load env from file | --env-file .env |
--restart | Restart policy | --restart unless-stopped |
--rm | Auto-remove on stop | --rm (for temp containers) |
Resource Constraints
# Memory: limit + reservation
docker run --memory=512m --memory-reservation=256m myapp
# CPU: shares (relative) + cpus (absolute)
docker run --cpus=2 --cpu-shares=1024 myapp
# Combined: production-grade limits
docker run -d \
--memory=1g --memory-swap=1g \
--cpus=2 \
--pids-limit=100 \
myapp
| Resource | Flag | Best Practice |
|---|---|---|
| Memory | --memory=512m | Always set; container can exhaust host memory otherwise |
| Memory+Swap | --memory-swap=1g | Set equal to memory to disable swap |
| CPU | --cpus=2 | Hard limit; --cpu-shares for relative priority |
| PIDs | --pids-limit=100 | Prevent fork bombs |
| Ulimits | --ulimit nofile=65536 | File descriptor limits |
Health Checks
Dockerfile HEALTHCHECK
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
Health Check States
starting → healthy (passes)
→ unhealthy (fails 3 consecutive checks)
# Check health status
docker inspect --format='{{.State.Health.Status}}' myapp
# Health check in compose
# services.app.healthcheck.test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
Restart Policies
| Policy | Behavior | Use Case |
|---|---|---|
no | Never restart (default) | One-off tasks |
on-failure[:N] | Restart on non-zero exit, max N times | Batch jobs |
always | Always restart | Critical services (be careful — infinite loop risk) |
unless-stopped | Restart unless explicitly stopped | Recommended for most services |
docker run --restart unless-stopped myapp
docker update --restart always myapp # Change policy on running container
Logging & Debugging
# View logs
docker logs myapp # All logs
docker logs -f myapp # Follow (tail -f)
docker logs --tail 50 myapp # Last 50 lines
docker logs --since 10m myapp # Last 10 minutes
# Execute commands in container
docker exec -it myapp sh # Interactive shell
docker exec myapp cat /etc/hosts # Run single command
# Inspect state
docker inspect myapp # Full JSON metadata
docker stats myapp # Live resource usage
docker top myapp # Running processes
docker port myapp # Port mappings
Signal Handling
docker stop myapp → SIGTERM → wait 10s → SIGKILL
docker kill myapp → SIGKILL immediately
docker kill -s HUP myapp → Send custom signal
| Signal | docker command | Container effect |
|---|---|---|
| SIGTERM | docker stop | Graceful shutdown (default) |
| SIGKILL | docker kill | Force kill (no cleanup) |
| SIGHUP | docker kill -s HUP | Reload config (app-specific) |
Workflow — 推荐操作流程
Step 1: 拉取或构建镜像: docker pull 或 docker build 准备好镜像
Step 2: 运行容器: docker run -d --name myapp -p 8080:8080 -v data:/data --memory 512m myapp
Step 3: 验证启动: docker ps + docker logs myapp 确认运行正常
Step 4: 配置健康检查: 确保 HEALTHCHECK 在 Dockerfile 中定义或运行时指定
Step 5: 监控运行: docker stats + docker logs -f 持续观察
Gotchas — Common Pitfalls
- Default
--memory=0(unlimited): Container can consume all host memory. → Recovery:docker run --memory=512m --cpus=1 app; check usage withdocker stats. docker stoptimeout: Default 10s grace period. → Recovery:docker stop -t 30 myapp; ensure app handles SIGTERM properly.docker runcreates new container: Runningdocker run nginxtwice creates two containers. → Recovery:docker start <existing-name>to restart;docker ps -ato find stopped containers.- Logs filling disk: JSON-file driver has no rotation by default. → Recovery:
docker run --log-opt max-size=10m --log-opt max-file=3 app; existing containers: edit/etc/docker/daemon.json+ restart dockerd. docker execexit codes: Returns the command's exit code. → Recovery: Use for scripting:docker exec myapp healthcheck.sh || exit 1.
Boundary — 能力边界(适用与不适用场景)
| 分类 | 场景 | 说明 |
|---|---|---|
| ✅ 能做 | docker run 运行容器 | 所有参数、资源限制、重启策略 |
| ✅ 能做 | 健康检查配置 | HEALTHCHECK 指令 + 运行时覆盖 |
| ✅ 能做 | 日志管理 | 日志驱动选择 + 轮转配置 |
| ✅ 能做 | 进入容器调试 | docker exec / docker attach |
| ⚠️ 需条件 | --privileged 特权模式 | 仅调试用,生产禁止 |
| ⚠️ 需条件 | 修改运行中容器限制 | 需 docker update,部分参数不可动态改 |
| ❌ 超范围 | 编写 Dockerfile | 使用 docker-dockerfile |
| ❌ 超范围 | 多容器编排 | 使用 docker-compose |
| ❌ 超范围 | 镜像构建 | 使用 docker-build |
When NOT to Use This Skill
| ❌ Skip | ✅ Use Instead |
|---|---|
| Docker basics / first-time setup | docker-basics |
| Writing Dockerfile | docker-build |
| Multi-container apps | docker-compose |
| Network configuration | docker-networking |
| Storage/Volume management | docker-storage |
Security & Stability
- Always set
--memoryand--cpuslimits in production to prevent noisy-neighbor issues. - Avoid
--privilegedflag. Use specific--cap-addinstead. - Never run containers as root. Use
--userflag orUSERin Dockerfile. - Use
--read-onlyfor stateless containers where possible. - No executable scripts bundled. Guidance only.
📚 官方文档参考
🧭 Docker Skills Journey
📍 You are here:
docker-run— Step 3: 容器管理与运维
← Previous: docker-build — Dockerfile & 镜像构建
→ Next: docker-networking / docker-storage / docker-compose
FAQ
What does the docker-run skill do?
Guidance for running and managing Docker containers. Covers the complete container lifecycle (create/start/stop/rm/restart), resource constraints (--memory/--cpus), health checks (HEALTHCHECK), restart policies, logging drivers, container inspection (inspect/stats/top), exec debugging, and signal handling. Use when the user asks about docker run, container management, resource limits, health checks, docker logs, docker exec, restart policies, or needs to manage running containers. 使用场景:docker run、容器管理、资源限制、健康检查、重启策略、docker logs、docker exec、docker ps.
How do I install docker-run?
Run npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-run in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/docker-run/ (personal) or .claude/skills/docker-run/ (project).
Which AI agents can use docker-run?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is docker-run safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains docker-run?
It is published by full-stack-skills in full-stack-skills/docker-skills. It has 100 recorded installs.
More from full-stack-skills/docker-skills
docker-compose
full-stack-skills/docker-skills
Expert guidance for Docker Compose — writing production-grade compose.yml files for multi-container applications. Covers complete Compose file syntax (services, networks, volumes, secrets, configs, profiles, extends, include), service configuration (image/build, ports, environment, envfile, dependson with health checks, deploy resources, restart policies), networking in Compose (default networks, custom networks, internal networks), volume management, environment variable strategies (.env vs environment vs envfile), override files for multi-environment, profiles for optional services, and migration to Kubernetes with kompose. Use when the user asks about docker compose, docker-compose.yml, compose file, multi-container, service orchestration, compose configuration, or needs to write/modify a compose file. 使用场景:docker compose、docker-compose.yml、compose 文件、多容器、服务编排、compose 配置、dependson、profiles.
docker-dockerfile
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-security
full-stack-skills/docker-skills
Guidance for Docker security hardening across the full lifecycle — image security (minimal base images, non-root users, pinned versions), runtime security (seccomp/AppArmor/SELinux, capabilities, read-only rootfs, no-new-privileges), secrets management (BuildKit secrets, Docker secrets in Swarm), Docker Bench Security auditing, CIS compliance checklist, and supply-chain security (image signing, content trust, SBOM). Use when the user asks about Docker security, image hardening, non-root containers, seccomp, AppArmor, Docker Bench, secrets management, or securing containers. 使用场景:docker 安全、镜像安全、非root运行、seccomp、AppArmor、security、Docker Bench、secret管理.
docker-troubleshooting
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-networking
full-stack-skills/docker-skills
Guidance for Docker networking configuration and inter-container communication. Covers network modes (bridge/host/overlay/none/macvlan/ipvlan), custom bridge networks with DNS resolution, port publishing (-p/--publish), container linking and service discovery, network troubleshooting (inspect/ping/nslookup), overlay networks for Swarm, and network security (internal networks, encrypted overlay). Use when the user asks about docker network, container networking, bridge mode, port mapping, inter-container communication, network troubleshooting, or Docker network modes. 使用场景:docker network、容器网络、bridge、overlay、端口映射、容器通信、网络配置、网络排查.
docker-basics
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
Popular devops & cloud skills
microsoft-foundry
microsoft/azure-skills
Build, deploy, evaluate, optimize, fine-tune, and manage Microsoft Foundry agents, models, and resources end to end. USE FOR: foundry, azd ai agent, azd provision/deploy, hosted agent scaffold/develop/run/deploy/troubleshoot, prompt agent create, managed harness agent create, GitHub Copilot harness agent, create agent, update agent, add tool to agent, invoke agent, agent insights, evaluate agent, batch eval, continuous eval, continuous monitoring, agent CI/CD, optimize prompt, improve prompt, optimize agent instructions, Agent Optimizer scaffold, dataset curation from traces, deploy model, model fine-tuning (SFT/DPO/RFT), Foundry project, RBAC, role assignment, permissions, quota, capacity, region, deployment failure, AI Services, create Foundry resource, knowledge index, customize deployment, onboard, availability, training-data, grader, distillation, large file upload. DO NOT USE FOR: Azure Functions, App Service, general Azure deploy (use azure-deploy), general Azure prep (use azure
azure-diagnostics
microsoft/azure-skills
Debug Azure production issues on Azure using AppLens, Azure Monitor, resource health, and safe triage. WHEN: debug production issues, troubleshoot app service, app service high CPU, app service deployment failure, troubleshoot container apps, container app 503 or target port mismatch, troubleshoot functions, function telemetry missing or stopped after a config/connection-string change, troubleshoot AKS, VM RDP, Linux SSH, VM black screen, can't connect to VM, reset VM password, NSG or firewall blocking, kubectl cannot connect, kube-system/CoreDNS failures, pod pending, crashloop, node not ready, upgrade failures, analyze logs, KQL, insights, image pull failures, cold start issues, health probe failures, resource health, root cause of errors, troubleshoot event hubs, troubleshoot service bus, messaging SDK error, AMQP connection failure, message lock lost, lock renewal during long-running processing, service bus dead letter.
azure-prepare
microsoft/azure-skills
Prepare azd-based Azure projects for deployment: generates azure.yaml, infrastructure (Bicep/Terraform), and Dockerfiles for the Azure Developer CLI (azd) workflow. USE ONLY when the user explicitly wants to use azd as the deployment tool, or the project already has an azure.yaml file. DO NOT USE FOR: non-azd deployments, Python App Service code-only deploys (use python-appservice-deploy), or cross-cloud migration (use azure-cloud-migrate). WHEN: prepare app for azd, create azure.yaml, set up azd infrastructure, modernize app for Azure with azd, deploy with azd, function app, timer trigger, service bus trigger, event-driven function, managed identity, generate Bicep, generate Terraform, create and deploy to Azure.
azure-ai
microsoft/azure-skills
Use for Azure AI: Search, Speech, OpenAI, Document Intelligence. Helps with search, vector/hybrid search, speech-to-text, text-to-speech, transcription, OCR. WHEN: AI Search, query search, vector search, hybrid search, semantic search, speech-to-text, text-to-speech, transcribe, OCR, convert text to speech.
azure-deploy
microsoft/azure-skills
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: "run azd up", "run azd deploy", "execute deployment", "push to production", "push to cloud", "go live", "ship it", "bicep deploy", "terraform apply", "publish to Azure", "launch on Azure". DO NOT USE WHEN: "create and deploy", "build and deploy", "create a new app", "set up infrastructure", "create and deploy to Azure using Terraform" — use azure-prepare for these.
azure-validate
microsoft/azure-skills
Pre-deployment validation for Azure readiness. Run deep checks on configuration, infrastructure (Bicep or Terraform), RBAC role assignments, managed identity permissions, and prerequisites before deploying. WHEN: validate my app, check deployment readiness, run preflight checks, verify configuration, check if ready to deploy, validate azure.yaml, validate Bicep, test before deploying, troubleshoot deployment errors, validate Azure Functions, validate function app, validate serverless deployment, verify RBAC roles, check role assignments, review managed identity permissions, what-if analysis, validate Container Apps deployment.