50 个常用 Docker 命令

1. Docker 基础命令

  • 查看 Docker 版本
bash 复制代码
docker --version
  • 查看 Docker 运行状态
bash 复制代码
systemctl status docker
  • 查看 Docker 信息
bash 复制代码
docker info
  • 查看帮助信息
bash 复制代码
docker help

2. 镜像管理

  • 拉取镜像
bash 复制代码
docker pull <镜像名>
  • 查看本地镜像
bash 复制代码
docker images
  • 删除镜像
bash 复制代码
docker rmi <镜像ID>
  • 删除未使用的镜像
bash 复制代码
docker image prune
  • 标记镜像
bash 复制代码
docker tag <源镜像> <目标镜像>
  • 推送镜像到 Docker Hub
bash 复制代码
docker push <镜像名>:<标签>
  • 查看镜像的详细信息
bash 复制代码
docker inspect <镜像ID>

3. 容器管理

  • 运行容器
bash 复制代码
docker run <镜像名>
  • 运行容器并进入交互模式
bash 复制代码
docker run -it <镜像名> /bin/bash
  • 查看正在运行的容器
bash 复制代码
docker ps
  • 查看所有容器(包括停止的)
bash 复制代码
docker ps -a
  • 停止容器
bash 复制代码
docker stop <容器ID>
  • 启动已停止的容器
bash 复制代码
docker start <容器ID>
  • 重启容器
bash 复制代码
docker restart <容器ID>
  • 删除容器
bash 复制代码
docker rm <容器ID>
  • 删除所有停止的容器
bash 复制代码
docker container prune
  • 进入正在运行的容器
bash 复制代码
docker exec -it <容器ID> /bin/bash
  • 查看容器日志
bash 复制代码
docker logs <容器ID>
  • 查看容器的资源使用情况
bash 复制代码
docker stats
  • 查看容器的环境变量
bash 复制代码
docker exec <容器ID> printenv
  • 复制文件到容器
bash 复制代码
docker cp <本地路径> <容器ID>:<容器路径>
  • 从容器复制文件到本地
bash 复制代码
docker cp <容器ID>:<容器路径> <本地路径>

4. 网络管理

  • 查看网络
bash 复制代码
docker network ls
  • 创建网络
bash 复制代码
docker network create <网络名>
  • 连接容器到网络
bash 复制代码
docker network connect <网络名> <容器ID>
  • 断开容器与网络的连接
bash 复制代码
docker network disconnect <网络名> <容器ID>

5. 卷管理

  • 查看卷
bash 复制代码
docker volume ls
  • 创建卷
bash 复制代码
docker volume create <卷名>
  • 删除卷
bash 复制代码
docker volume rm <卷名>

6. Dockerfile 和镜像构建

  • 创建 Dockerfile
bash 复制代码
touch Dockerfile
  • 构建镜像
bash 复制代码
docker build -t <镜像名>:<标签> .
  • 导出容器为 tar 文件
bash 复制代码
docker export <容器ID> > <文件名>.tar
  • 导入 tar 文件为镜像
bash 复制代码
cat <文件名>.tar | docker import - <镜像名>

7. Docker Compose

  • 使用 Docker Compose 启动服务
bash 复制代码
docker-compose up
  • 使用 Docker Compose 停止服务
bash 复制代码
docker-compose down
  • 查看 Docker Compose 服务状态
bash 复制代码
docker-compose ps
  • 构建 Docker Compose 服务
bash 复制代码
docker-compose build

8. 系统与日志管理

  • 查看 Docker 守护进程日志
bash 复制代码
journalctl -u docker.service
  • 查看 Docker 事件
bash 复制代码
docker events

9. 资源限制

  • 启动守护进程模式的容器
bash 复制代码
docker run -d <镜像名>
  • 使用特定端口运行容器
bash 复制代码
docker run -p <主机端口>:<容器端口> <镜像名>
  • 限制容器的 CPU 使用
bash 复制代码
docker run --cpus=<数量> <镜像名>
  • 限制容器的内存使用
bash 复制代码
docker run -m <内存限制> <镜像名>

我是晓凡,再小的帆也能远航

希望内容对您有所帮助

我们下期再见 ヾ(•ω•`)o (●'◡'●)

相关推荐
代码游侠4 小时前
ARM开发——阶段问题综述(二)
运维·arm开发·笔记·单片机·嵌入式硬件·学习
Mr.朱鹏5 小时前
Nginx路由转发案例实战
java·运维·spring boot·nginx·spring·intellij-idea·jetty
java_logo5 小时前
OpenCode 企业级 Docker 部署完整指南
运维·docker·容器·opencode·opencode本地化部署·opencode部署手册·opencode部署方案
再战300年5 小时前
docker下创建redis集群方案
redis·docker·容器
TTBIGDATA7 小时前
【knox】User: knox is not allowed to impersonate admin
大数据·运维·ambari·hdp·trino·knox·bigtop
qq_229058017 小时前
docker中检测进程的内存使用量
java·docker·容器
佑白雪乐7 小时前
<Linux基础第10集>复习前面内容
linux·运维·服务器
java_logo7 小时前
使用 Docker 部署 Clawdbot(官方推荐方式)
docker·容器·clawdbot·clawdbot部署·clawdbot部署手册·clawdbot部署文档·docker clawdbot
春日见7 小时前
自动驾驶规划控制决策知识点扫盲
linux·运维·服务器·人工智能·机器学习·自动驾驶