
获取镜像
# 从镜像仓库中查找镜像
$ docker search [image name]
# 从镜像仓库中查找 stars 大于 10 的镜像
$ docker search --filter stars=10 [image name]
# 从镜像仓库中下载或更新指定镜像
$ docker pull [image name][:tag]
# 从镜像仓库中下载指定的所有镜像
$ docker pull -a [image name]
镜像操作
# 列出本地镜像
$ docker images
# 删除(一个或多个)本地镜像
$ docker rmi [image name...]
# 强制删除(一个或多个)本地镜像
$ docker rmi -f [image name...]
# 更新镜像
$ docker commit -m=[commit message] -a=[author] [container id] [image name]
# 使用 Dockerfile 构建镜像
$ docker build -t [image name] [dockerfile path]
# 将指定镜像文件保存为 tar 归档文件
$ docker save -o [path] [image name]
# 导入(使用 docker save 命令导出的)归档文件
$ docker load -i [path]
# 导入归档文件
$ docker import [path] [image name]
容器操作
# 列出正在运行的容器
$ docker ps
# 列出所有容器
$ docker ps -a
# 将文件系统保存为 tar 归档文件
$ docker export -o [path] [container name]
# 查看指定容器的端口映射
$ docker port [container name]
容器的生命周期管理
# 使用镜像创建容器,并后台运行
$ docker run -d --name [container name] [image name]
# 创建容器,并将容器端口映射到宿主端口
$ docker run -d --name [container name] -p [local port]:[container port] [image name]
# 启动(一个或多个)已停止的容器
$ docker start [container name...]
# 关闭(一个或多个)运行中的容器
$ docker stop [container name...]
# 重启(一个或多个)容器
$ docker restart [container name...]
# 杀掉一个运行中的容器
$ docker kill [container name]
# 删除(一个或多个)容器
$ docker rm [container name...]
# 创建一个容器但不启动它
$ docker create --name [container name] [image name]
# 在 bash 中执行容器
$ docker exec -it [container name] /bin/bash
docker --help
Commands:
attach Attach local standard input, output, and error streams to a running container
将本地标准输入、输出和错误流连接到运行中的容器
build Build an image from a Dockerfile
从Dockerfile中构建镜像
commit Create a new image from a container's changes
从container的变化中创建新image
cp Copy files/folders between a container and the local filesystem
在一个container和本地文件系统之间拷贝文件/文件夹
create Create a new container
创建一个新的container
diff Inspect changes to files or directories on a container's filesystem
检查容器文件系统中文件或目录的更改
events Get real time events from the server
从服务器获取实时事件
exec Run a command in a running container
在一个运行中的container中运行一条命令
export Export a container's filesystem as a tar archive
将容器的文件系统导出为tar存档
history Show the history of an image
展示一个image的历史
images List images
列出images
import Import the contents from a tarball to create a filesystem image
从压缩包中导入内容,创建一个文件系统镜像
info Display system-wide information
显示整个系统的信息
inspect Return low-level information on Docker objects
返回Docker对象的底层信息
kill Kill one or more running containers
杀死一个或多个运行中的container
load Load an image from a tar archive or STDIN
从一个压缩存档或STDIN中载入一个image
login Log in to a Docker registry
登录Docker注册表
logout Log out from a Docker registry
从注册中心登出
logs Fetch the logs of a container
从container中抓取日志
pause Pause all processes within one or more containers
暂停一个或多个container内的所有进程
port List port mappings or a specific mapping for the container
列出容器的端口映射或特定映射
ps List containers
列出所有容器
pull Pull an image or a repository from a registry
从注册表中拉出一个镜像或一个存储库
push Push an image or a repository to a registry
推送一个镜像或存储库到注册表
rename Rename a container
重命名一个容器
restart Restart one or more containers
重启一个或多个容器
rm Remove one or more containers
移除一个或多个容器
rmi Remove one or more images
移除一个或多个镜像
run Run a command in a new container
在一个新容器中运行一条命令
save Save one or more images to a tar archive (streamed to STDOUT by default)
保存一个或多个镜像为一个压缩存档(默认为流向STDOUT)
search Search the Docker Hub for images
在Dockers Hub中搜索镜像
start Start one or more stopped containers
启动一个或多个停止的容器
stats Display a live stream of container(s) resource usage statistics
显示容器资源使用统计的实时流
stop Stop one or more running containers
停止一个或多个运行中的容器
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
创建一个指向SOURCE_IMAGE标签TARGET_IMAG
top Display the running processes of a container
显示一个容器所有正在运行中的进程
unpause Unpause all processes within one or more containers
解除一个或多个容器内的所有进程的暂停
update Update configuration of one or more containers
更新一个或多个容器的配置
version Show the Docker version information
展示容器的版本信息
wait Block until one or more containers stop, then print their exit codes
阻塞直到一个或多个容器停止,然后打印它们的退出代码
Run 'docker COMMAND --help' for more information on a command.