Docker基础命令、镜像相关命令

1. Docker 基础命令

1.1 查看docker状态

systemctl status docker

1.2 启动docker服务

systemctl start docker

1.3 重启docker服务

systemctl restart docker
systemctl daemon-reload # 重启守护进程

1.4 停止docker服务

systemctl stop docker

1.5 设置开机启动

systemctl enalbe docker

1.6 查看Docker概要信息

docker info
docker version

1.7 查看Docker帮助信息

docker --help
docker 具体命令 --help

1.8 docker system、查看镜像、容器、数据卷所占空间

docker system COMMAND
Commands:
  df          Show docker disk usage
  events      Get real time events from the server
  info        Display system-wide information
  prune       Remove unused data

docker system df # 查看镜像、容器、数据卷所占空间

2. 镜像相关命令

2.1 查看本地镜像、镜像信息、镜像历史

命令格式

docker images [OPTIONS] [REPOSITORY[:TAG]]

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs
docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects
Options:
  -f, --format string   Format the output using the given Go template
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type

示例

docker images
docker images –q # 查看所有镜像的id
docker inspect 镜像名称 # 查看镜像信息
# 展示一个镜像形成历史
docker history [OPTIONS] IMAGE

Show the history of an image
Options:
      --format string   Pretty-print images using a Go template
  -H, --human           Print sizes and dates in human readable format (default true)
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs

2.2 搜索镜像

docker search [OPTIONS] 镜像名称

#常用选项
--limit #返回镜像信息条数,默认25条

#示例
docker search 镜像名称:镜像版本
docker search --limit 5 镜像名称:镜像版本

2.3 拉取镜像

#命令格式
docker pull [OPTIONS] NAME[:TAG|@DIGEST]

#示例
docker pull 镜像名称:镜像版本

# 如果不指定版本,则默认拉去最新版,不知道版本可以访问 https://hub.docker.com/ 查询;

2.4 删除镜像

# 命令格式
docker rmi [OPTIONS] IMAGE [IMAGE...]
Options:
  -f, --force      Force removal of the image #强制删除
      --no-prune   Do not delete untagged parents


#删除单个
docker rmi 镜像id或名称 # 删除指定本地镜像

#删除多个
docker rmi 镜像名1:版本 镜像名2:版本 镜像名3:版本···

#删除所有
docker rmi `docker images -aq` # 删除所有本地镜像

2.5 创建某个容器的镜像

# 命令格式
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <[email protected]>")
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)

#示例
docker commit -a="sven" -m="配置JDK8" 容器ID IMAGE_NAME:TAG

2.6 镜像的导入与导出 docker save/load

导出

#命令格式
docker save [OPTIONS] IMAGE [IMAGE...]
# 含义及参数
Save one or more images to a tar archive (streamed to STDOUT by default)
Options:
  -o, --output string   Write to a file, instead of STDOUT

#示例
docker save -o ubuntu_20_04.tar ubuntu:20.04 # 打包一个镜像
docker save -o images.tar postgres:9.6 mongo:3.4 # 打包多个镜像到一个tar中

导入

#命令格式
docker load [OPTIONS]
# 含义及参数
Load an image from a tar archive or STDIN
Options:
  -i, --input string   Read from tar archive file, instead of STDIN
  -q, --quiet          Suppress the load output

#示例
docker load -i ubuntu_20_04.tar

2.7 容器的导入与导出 docker export/import

导出

#命令格式
docker export [OPTIONS] CONTAINER
# 含义及参数
Export a container's filesystem as a tar archive
Options:
  -o, --output string   Write to a file, instead of STDOUT

#示例
docker export -o ubuntu_20_04.tar 容器id或名字

导入

#命令格式
docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
# 含义及参数
Import the contents from a tarball to create a filesystem image
Options:
  -c, --change list       Apply Dockerfile instruction to the created image
  -m, --message string    Set commit message for imported image
      --platform string   Set platform if server is multi-platform capable

#示例
docker import xxx.tar image_name:tag

参考连接:

docker 帮助文档

https://blog.csdn.net/JineD/article/details/118761569

猜你喜欢

转载自blog.csdn.net/weixin_52341477/article/details/127767429