docker命令行的使用
docker命令行是docker用户和docker守护进程交互的主要途径。普通用户主要使用命令行接口来管理配置、管理和操作docker
docker命令行接口类型
docker是一个庞大而复杂的平台,其命令行接口可分为以下几种类型:
- 引擎命令行接口(Engine CLI):这是docker最主要的命令行,包括所有的docker命令和dockerd命令,其中docker命令是最常用的。
- 容器编排命令行接口(Compose CLI):这是docker compose工具所提供的,用来让用户构建并运行多容器的应用程序。
- 机器命令行接口(Machine CLI):这是docker machine工具所提供的,用于配置和管理远程docker主机。
- DTR命令行接口:部署和管理docker可信注册中心(Trusted Registry)。
- UCP命令行接口:部署和管理通用控制面板(Universal Control Plane)。
docker命令列表
通过不带任何选项和参数的docker命令可以得到一份完整的命令列表
[root@redhat01 ~]# docker
Usage: docker [OPTIONS] COMMAND //用法
A self-sufficient runtime for containers
Common Commands: //常用命令
run Create and run a new container from an image //从镜像创建并运行一个新容器
exec Execute a command in a running container //在运行中的容器中执行命令
ps List containers //列出容器
build Build an image from a Dockerfile //从Dockerfile构建镜像
pull Download an image from a registry //从注册表下载映像
push Upload an image to a registry //上传图像到注册表
images List images //列出镜像
login Log in to a registry //登录注册表
logout Log out from a registry //从注册中心注销
search Search Docker Hub for images //搜索Docker Hub查找镜像
version Show the Docker version information //显示Docker版本信息
info Display system-wide information //显示系统范围的信息
Management Commands: //管理命令
builder Manage builds //管理构建
buildx* Docker Buildx
compose* Docker Compose
container Manage containers //管理容器
context Manage contexts //管理上下文
image Manage images //管理镜像
manifest Manage Docker image manifests and manifest lists //管理Docker镜像清单和清单列表
network Manage networks //管理网络
plugin Manage plugins //管理插件
system Manage Docker //管理docker本身
trust Manage trust on Docker images //管理docker镜像上的信任
volume Manage volumes //管理卷
Swarm Commands:
swarm Manage Swarm
Commands: //命令
attach Attach local standard input, output, and error streams to a running container //附加到正在运行的容器上的本地标准输入、输出和错误流
commit Create a new image from a container's changes //基于修改的容器创建新的镜像
cp Copy files/folders between a container and the local filesystem //在容器与本地文件系统之间复制文件或目录
create Create a new container //创建新的容器
diff Inspect changes to files or directories on a container's filesystem //查看容器的文件系统上的文件或目录的变化
events Get real time events from the server //获取来自服务器的实时事件
export Export a container's filesystem as a tar archive //将容器的文件系统导出为Tar归档文件
history Show the history of an image //显示镜像的历史
import Import the contents from a tarball to create a filesystem image //从tarball中导入内容以创建文件系统映像
inspect Return low-level information on Docker objects //返回Docker对象的底层信息
kill Kill one or more running containers //杀死一个或多个正在运行的容器
load Load an image from a tar archive or STDIN //从tar存档文件或STDIN加载图像
logs Fetch the logs of a container //获取容器的日志
pause Pause all processes within one or more containers //暂停一个或多个容器中的所有进程
port List port mappings or a specific mapping for the container //列出端口映射或容器的特定映射
rename Rename a container //重命名容器
restart Restart one or more containers //重新启动一个或多个容器
rm Remove one or more containers //移除一个或多个容器
rmi Remove one or more images //删除一个或多个镜像
save Save one or more images to a tar archive (streamed to STDOUT by default) //将一个或多个图像保存到tar存档(默认情况下流式传输到STDOUT)
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_IMAGE
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 //更新一个或多个容器的配置
wait Block until one or more containers stop, then print their exit codes //阻塞直到一个或多个容器停止,然后打印它们的退出代码
Global Options: //全局选项
--config string Location of client config files (default "/root/.docker") //客户端配置文件
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env
var and default context set with "docker context use") //用于连接到守护进程的上下文名称(覆盖DOCKER_HOST env)
Var和默认上下文设置为“docker context use”)
-D, --debug Enable debug mode //启用调用模式
-H, --host list Daemon socket to connect to //要连接的守护进程套接字
-l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info") //设置日志级别("debug", "info", "warn", "error", "fatal")(默认为"info")
--tls Use TLS; implied by --tlsverify //使用TLS;由——tlsverify暗示
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") //仅由该CA签署的信任证书(默认为“/root/.docker/ CA .pem”)
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") //TLS证书文件路径(默认为“/root/.docker/cert.pem”)
--tlskey string Path to TLS key file (default "/root/.docker/key.pem") //TLS密钥文件路径(默认为“/root/.docker/key.pem”)
--tlsverify Use TLS and verify the remote //使用TLS并验证远程
-v, --version Print version information and quit //打印版本信息并退出
Run 'docker COMMAND --help' for more information on a command.
For more help on how to use Docker, head to https://docs.docker.com/go/guides/
该命令最后提示可以运行docker COMMAND --help
命令来查看某条具体子命令的帮助信息。例如,查看tag子命令的帮助信息:
[root@redhat01 ~]# docker tag --help
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Aliases:
docker image tag, docker tag
用法:docker标签SOURCE_IMAGE[: tag] TARGET_IMAGE[: tag]
创建一个指向SOURCE_IMAGE的标签TARGET_IMAGE
别名:
Docker图像标签,Docker标签
考虑到功能和应用场景,可将这些大致分为以下4个类别。
- 系统信息:如info、version
- 系统运维:如attach、build、commit、run等
- 日志信息:如events、histoty、logs等
- Docker注册:如login、pull、push、search等
docker命令的基本用法
docker命令采用的是Linux命令语法格式,可以使用选项和参数。docker官方文档中有的地方将不带参数的选项称为flag(标志),为了便于表述。
docker [OPTIONS] COMMAND
其中OPTIONS表示选项,COMMAND是docker命令的子命令。