企业级 Docker 运维命令速查表

企业级 Docker 运维命令速查表


一、服务状态与基础排查(⭐⭐⭐⭐⭐)

1. 查看容器状态(第一反应)

bash 复制代码
docker ps
docker ps -a

常用组合:

bash 复制代码
docker ps | grep 服务名

2. 查看日志(80% 问题来源)

bash 复制代码
docker logs 容器名
docker logs -f 容器名
docker logs --tail 200 容器名

多服务(Compose):

bash 复制代码
docker compose logs
docker compose logs -f 服务名

3. 进入容器排障

bash 复制代码
docker exec -it 容器名 bash
docker exec -it 容器名 sh

二、Docker Compose 运维(⭐⭐⭐⭐⭐)

4. 启动 / 发布

bash 复制代码
docker compose up -d
docker compose up -d --build

5. 停止 / 下线

bash 复制代码
docker compose stop
docker compose down

6. 查看服务状态

bash 复制代码
docker compose ps

三、资源与性能监控(⭐⭐⭐⭐)

7. 实时资源使用

bash 复制代码
docker stats

查看:

  • CPU
  • Memory
  • Network
  • Block IO

8. 容器详细信息(高级排障)

bash 复制代码
docker inspect 容器名

常用字段:

bash 复制代码
docker inspect --format '{{.State.Status}}' 容器名
docker inspect --format '{{.NetworkSettings.IPAddress}}' 容器名

四、镜像管理(⭐⭐⭐⭐)

9. 镜像列表

bash 复制代码
docker images

10. 拉取镜像(上线前)

bash 复制代码
docker pull 镜像:版本

11. 删除镜像(清理磁盘)

bash 复制代码
docker rmi 镜像ID
docker rmi -f 镜像ID

五、网络排障(⭐⭐⭐)

12. 查看网络

bash 复制代码
docker network ls

13. 网络详情

bash 复制代码
docker network inspect 网络名

常用排查:

  • 容器是否在同一网络
  • DNS 是否正常

六、存储与数据(⭐⭐⭐)

14. Volume 列表

bash 复制代码
docker volume ls

15. Volume 详情

bash 复制代码
docker volume inspect volume名

16. 文件拷贝(紧急取证)

bash 复制代码
docker cp 容器名:/path/file .
docker cp localfile 容器名:/path/

七、清理与磁盘空间(⭐⭐⭐)

17. 磁盘占用情况

bash 复制代码
docker system df

18. 清理无用资源(慎用)

bash 复制代码
docker system prune
docker system prune -a

⚠️ 生产环境慎用 -a


八、容器控制(⭐⭐)

bash 复制代码
docker stop 容器名
docker start 容器名
docker restart 容器名

九、事件与异常排查(⭐⭐)

19. 查看 Docker 事件

bash 复制代码
docker events

用于排查:

  • OOM Kill
  • 容器频繁重启

十、GPU 运维专用(AI / 推理服务必备)

⭐⭐⭐⭐⭐ GPU 状态

bash 复制代码
nvidia-smi

⭐⭐⭐⭐ Docker GPU 可用性

bash 复制代码
docker run --rm --gpus all nvidia/cuda:12.1.0-base nvidia-smi

⭐⭐⭐ 容器 GPU 配置确认

bash 复制代码
docker inspect 容器名 | grep -i nvidia

十一、企业级「运维场景 → 命令套路」

🚨 服务起不来

bash 复制代码
docker compose ps
docker compose logs -f 服务名

🚨 服务在但访问失败

bash 复制代码
docker ps
docker logs 容器名
docker exec -it 容器名 bash
curl localhost:端口

🚨 机器负载过高

bash 复制代码
docker stats
free -h
df -h

🚨 发布 / 回滚

bash 复制代码
docker pull 镜像:版本
docker compose up -d
docker compose logs -f

十二、必须形成"肌肉记忆"的 10 条命令

bash 复制代码
docker ps
docker logs -f
docker exec -it
docker compose up -d
docker compose logs -f
docker compose down
docker stats
docker inspect
docker system df
nvidia-smi

掌握这 10 条 = 已具备企业 Docker 运维能力

相关推荐
SkyWalking中文站1 天前
认识 Horizon UI · 1/17:SkyWalking 新一代可观测性控制台
运维·前端·监控
雪梨酱QAQ1 天前
Kubeneters HA Cluster部署
运维
lichenyang4531 天前
Docker 学习笔记(五):Docker Compose,用一个 YAML 启动前端、后端和 MongoDB
docker
lichenyang4531 天前
Docker 学习笔记(四):Dockerfile,把项目打成自己的镜像
docker·容器
lichenyang4531 天前
Docker 学习笔记(三):Docker 网络、bridge、子网和容器互通
docker·容器
lichenyang4531 天前
Docker 学习笔记(二):docker run 的参数到底在控制什么?
docker·容器
江华森1 天前
Spring Cloud 微服务全栈实战:从 Eureka 到 Docker Compose 一文贯通
运维
江华森1 天前
Matplotlib 数据绘图基础入门
运维
江华森1 天前
NumPy 数值计算基础入门
运维
乘云数字DATABUFF5 天前
5分钟部署开源APM Databuff:OpenTelemetry全链路追踪入门实战
运维·后端