对docker 常用的一些命令做一个记录
镜像 image 相关
## 拉去一个镜像文件docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]docker pull ubuntu:18.04## 查看镜像列表docker image lsdocker image ls -q -q是只列出id## 镜像列表过滤docker image ls -f dangling=true ## 虚悬镜像docker image ls -f since=mongo:3.2 ## 在指定的镜像之后创建的镜像docker image ls -f before=mongo:3.2 ## 在指定的镜像之前创建的镜像## 根据镜像名称和标签过滤docker image ls ubuntu docker image ls ubuntu:18.04 ## 删除虚悬镜像docker image prune ## 删除镜像docker image rm [选项] <镜像1> [<镜像2> ...]docker image rm d610e7d67ed0## 命令组合删除所有的镜像docker image rm $(docker image ls -q)## 构建一个新的imagedocker build [选项] <上下文路径/URL/->docker build -t nginx:v3 . 构建image
容器 container 相关
## 运行镜像生成容器docker run [选项] <镜像名称>docker run --name webserver -d -p 4000:80 nginx-d 是后端运行-p 宿主端口:容器内端口 端口映射## 进入container bashdocker exec -it [container名称] basheg:docker exec -it webserver bash## 提交容器docker commit [选项] <容器ID或容器名> [<仓库名>[:<标签>]]docker commit \ --author "cfl <cfl@qq.com>" \ --message "test" \ webserver \ nginx:v2## 提交历史docker history nginx:v2## container内容修改记录docker diff webserver
其他命令
## 查看镜像、容器、数据卷所占用的空间。docker system df