Detailed explanation of common Docker commands, these are enough

start class first


Start docker: systemctl start docker
Stop docker: systemctl stop docker
Restart docker: systemctl restart docker
View docker status: systemctl status docker
boot self-start: systemctl enable docker
View docker overview information: docker info
View docker overall help documentation: docker --help
view docker command help documentation: docker specific command --help

mirror command


docker images - list all images
list all images

all orders

docker detailed command supplementary instructions

Order illustrate
docker attach Attach local standard input, output and error streams to a running container
docker build Build an image from a Dockerfile
docker builder Manage builds
docker checkpoint Manage Checkpoints
docker commit Create new images from container changes
docker config Manage Docker configuration
docker container Manage Containers
docker context management context
docker cp Copy files/folders between container and local filesystem
docker create create a new container
docker diff Check for changes to a file or directory on the container's filesystem
docker events Get real-time events from the server
docker exec Run the command in a running container
docker export Export the container's filesystem as a tar archive
docker history display image history
docker image Manage images
docker images image list
docker import Create a new file system from the contents of the tarball and import it as an image
docker info Display information about the entire system
docker inspect Returns low-level information about a Docker object
docker kill kill one or more running containers
docker load Load image from tar archive or STDIN
docker login Log in to the Docker registry
docker logout Unregister from the Docker registry
docker logs Get container logs
docker manifest Manage Docker image manifests and manifest lists
docker network management network
docker node Management group node
docker pause suspend all processes inside one or more containers
docker plugin Manage plugins
docker port List port mappings or specific mappings for a container
docker ps list containers
docker pull Pull an image or repository from a registry
docker push Push an image or repository to a registry
docker rename heavy naming container
docker restart restart one or more containers
docker rm remove one or more containers
docker rmi delete one or more images
docker run Run the command in the new container
docker save Save one or more images to a tar archive (streaming to STDOUT by default)
docker search Search for images in Docker Hub
docker secret Manage Docker secrets
docker service management service
docker stack Manage the Docker stack
docker start Start one or more stopped containers
docker stats Displays a live stream of container resource usage statistics
docker stop Stop one or more running containers
docker swarm management group
docker system Manage Docker
docker tag Create a tag TARGET_IMAGE that references SOURCE_IMAGE
docker top Show the running process of the container
docker trust Manage trust in Docker images
docker unpause 取消暂停一个或多个容器内的所有进程
docker update 更新一个或多个容器的配置
docker version 显示Docker版本信息
docker volume 管理卷
docker wait 阻止直到一个或多个容器停止,然后打印它们的退出代码

使用

docker images [选项]

 显示的各个参数说明

REPOSITORY 表示镜像的仓库源
TAG 镜像的标签版本号
IMAGE ID 镜像ID
CREATED 镜像创建时间
SIZE 镜像大小
同一仓库源可以有多个 TAG版本,代表这个仓库源的不同个版本,我们使用 REPOSITORY:TAG 来定义不同的镜像。
如果你不指定一个镜像的版本标签,例如你只使用 ubuntu,docker 将默认使用 ubuntu:latest 镜像

选项

名称,简写 默认 描述
–all,-a   显示所有图像(默认隐藏中间图像)
–digests   显示摘要
–filter,-f   根据提供的条件过滤输出
–format   使用 Go 模板打印漂亮的图像
–no-trunc   不要截断输出
–quiet,-q   仅显示图像 ID

docker search-搜索镜像

在Docker Hub中搜索镜像

使用

docker search [选项] 镜像名称

 选项

名称,简写 默认 描述
–filter , -f   根据提供的条件过滤输出
–format   使用Go模板的漂亮打印搜索
–limit 25 最大搜索结果数
–no-trunc   不要截断输出

docker pull-下载镜像

下载某个镜像

使用

docker pull 镜像名称[:TAG]

省略TAG默认为最新版

选项 

名称,简写 默认 描述
–all-tags,-a   下载存储库中的所有标记图像
–disable-content-trust TRUE 跳过图像验证
–platform   如果服务器支持多平台,则设置平台
–quiet,-q   抑制详细输出

docker system df-显示docker磁盘使用情况

查看镜像/容器/数据卷所占用的空间

使用

docker system df

docker rmi-删除镜像

删除一个或多个镜像

使用

docker rmi -f 镜像ID:删除一个
docker rmi -f 镜像名1:TAG 镜像名2:TAG :删除多个
docker rmi -f $(docker images -qa):删除全部

-f:表示强制删除

容器命令

docker run新建并启动容器

新建并启动容器

使用

docker run [选项] 镜像 [命令] [ARG...]

选项

名称,简写 描述 例子
–name 为容器指定名称 –name=myRedis
–detach,-d 在后台运行容器并打印容器ID  
–publish,-p 指定端口映射 #NAME?
#NAME?    
–publish-all,-P 随机端口映射
–interactive,-i 以交互模式运行容器,通常与-t同时使用
–tty,-t 为容器超星分配一个伪输入终端,通常与-i同时使用
也即启动交互式容器(前台有伪终端,等待交互)

 深度学习

docker rename-重命名容器

给容器重新命名


使用

docker rename 容器 新名称

docker ps-查看启动的容器

查看启动的容器


使用

docker ps [选项]

选项

名称,简写 默认 描述
–all,-a   显示所有容器(默认显示刚刚运行)
–filter,-f   根据提供的条件过滤输出
–format   使用 Go 模板打印漂亮的容器
–last,-n -1 显示 n 个最后创建的容器(包括所有状态)
–latest,-l 显示最新创建的容器(包括所有状态)
–no-trunc 不要截断输出
–quiet,-q 仅显示容器 ID
–size,-s 显示总文件大小

退出交互式

exit:退出后容器会停止
ctrl+p+q:退出后容器不会停止

docker start-启动容器

启动已经停止的一个或多个容器

使用
docker start [选项] 容器ID或名称 [容器ID或名称...]

docker restart-重启容器

重新启动一个或多个容器

使用
docker restart [选项] 容器ID或名称 [容器ID或名称...]

选项

名称,简写 默认 描述
–time , -t 10 在杀死容器之前等待停止的秒数

docker stop-停止容器

停止一个或多个正在运行的容器

使用

docker stop [选项] 容器ID或名称 [容器ID或名称...]

选项

名称,简写 默认 描述
–time , -t 10 在杀死容器之前等待停止的秒数

docker kill-强行停止容器

杀死一个或多个正在运行的容器

使用

docker kill [选项] 容器ID或名称 [容器ID或名称...]

选项

名称,简写 默认 描述
–signal,-s KILL 发送到容器的信号

docker rm-删除容器

删除一个或多个容器

使用

docker rm [选项] 容器ID或名称 [容器ID或名称...]
一次性删除所有:

  • docker rm -f $(docker ps -a -q)
  • docker ps -a -q | xargs docker rm

选项

名称,简写 默认 描述
–force , -f   强制删除正在运行的容器(使用 SIGKILL)
–link,-l   删除指定链接
–volumes,-v   删除与容器关联的匿名卷

docker logs-查看容器日志

获取容器的日志

使用

docker logs [选项] 容器

 选项

名称,简写 默认 描述
–details   显示提供给日志的额外详细信息
–follow,-f   关注日志输出
–since   显示自时间戳(例如 2013-01-02T13:23:37Z)或相对时间(例如 42m 42 分钟)以来的日志
–tail,-n all 从日志末尾显示的行数
–timestamps,-t 显示时间戳
–until 在时间戳(例如 2013-01-02T13:23:37Z)或相对时间(例如 42m 42 分钟)之前显示日志

docker top-查看容器内运行的进程

显示容器的运行进程

使用

docker top 容器

docker inspect-查看容器内部细节

查看容器内部细节,返回有关 Docker 对象的低级信息

使用

docker inspect [选项] 容器

docker exec-在容器中运行命令

在正在运行的容器中运行命令

使用

docker exec [选项] 容器 命令 [ARG...]
docker exec -it 容器 命令

exec是在容器中打开新的终端,并且可以启动新的进程用exit退出,不会导致容器的停止。

选项

名称,简写

默认 描述
–detach , -d   分离模式:后台运行命令
–detach-keys   覆盖用于分离容器的键序列
–env,-e   设置环境变量
–env-file   读入环境变量文件
–interactive,-i 以交互模式运行容器,通常与-t同时使用
–privileged 赋予命令扩展权限
–tty,-t 为容器超星分配一个伪输入终端,通常与-i同时使用
也即启动交互式容器(前台有伪终端,等待交互)
–user,-u 用户名或 UID(格式:<name|uid>[:<group|gid>])
–workdir,-w 容器内的工作目录

docker attach-连接到正在运行中的容器

连接到正在运行中的容器

使用

docker attch 容器

attach 直接进入容器启动命令的终端,不会启动新的进程用exit退出,会导致容器的停止。

docker cp-复制文件

在容器和本地文件系统之间复制文件/文件夹

使用
容器内复制到本地:docker cp [选项] 容器:容器内路径 本地路径

如:docker cp aad23e144eac:/var/logs/ /tmp/app_logs
本地复制到容器内:docker cp [选项] 本地路径 容器:容器内路径

如:docker cp ./some_file aad23e144eac:/work

docker export-导出

将容器的文件系统导出为 tar 存档

使用

docker export [选项] 容器

  • 如: docker exprot 5ef6d98bd956 > nacos2.2.2.tar

docker import-导入

从tar包中的内容创建一个新的文件系统再导入为镜像

使用

docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

  • 如:  docker import nacos2.2.2.tar nacos:v2.1.1

 

Guess you like

Origin blog.csdn.net/Angel_asp/article/details/130268496