docker 命令

对docker 经常使用的一些命令作一个记录nginx

镜像 image 相关

## 拉去一个镜像文件
docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]
docker pull ubuntu:18.04

## 查看镜像列表
docker image ls
docker 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)

## 构建一个新的image
docker build [选项] <上下文路径/URL/->
docker build -t nginx:v3 . 构建image

容器 container 相关

## 运行镜像生成容器
docker run [选项] <镜像名称>
docker run --name webserver -d -p 4000:80 nginx
-d 是后端运行
-p 宿主端口:容器内端口   端口映射

## 进入container bash
docker exec -it [container名称] bash
eg: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

未完待续

相关文章
相关标签/搜索