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 (●'◡'●)

相关推荐
航Hang*7 小时前
Windows Server 配置与管理——第3章:文件系统管理
运维·服务器·windows·vmware
lifewange8 小时前
Linux ps 进程查看命令详解
linux·运维·服务器
功德+n8 小时前
Linux下安装与配置Docker完整详细步骤
linux·运维·服务器·开发语言·docker·centos
小敬爱吃饭8 小时前
Ragflow Docker部署及问题解决方案(界面为Welcome to nginx,ragflow上传文件失败,Docker中的ragflow-cpu-1一直重启)
人工智能·python·nginx·docker·语言模型·容器·数据挖掘
杨云龙UP8 小时前
从0到1快速学会Linux操作系统(基础),这一篇就够了!
linux·运维·服务器·学习·ubuntu·centos·ssh
HXQ_晴天8 小时前
Ubuntu 设置中文输入法
linux·运维·ubuntu
Dovis(誓平步青云)8 小时前
《Linux 信号入门:搞懂 “进程通信的紧急电话” 到底怎么用(初篇)》
linux·运维·服务器
0vvv09 小时前
删除wsl环境下的Ubuntu系统
linux·运维·ubuntu
木子欢儿9 小时前
Docker Hub 镜像发布指南
java·spring cloud·docker·容器·eureka