Docker3.Docker镜像操作

帮助命令

官放文档地址:(URL以docker build为例)
https://docs.docker.com/engine/reference/commandline/build/
biuild是docker build,比如查docker images,就URL替换build即可

目录:Reference / Command-line reference / Docker Compose CLI reference / Overviewof docker-compose CLI
在这里插入图片描述

docker version

#docker版本信息
docker version
[root@VM-0-3-centos ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 11:58:10 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:56:35 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@VM-0-3-centos ~]#


docker info

#docker详细信息
docker info
[root@VM-0-3-centos ~]# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc.)

Server:
 Containers: 4
  Running: 2
  Paused: 0
  Stopped: 2
 Images: 33
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1160.11.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 1.795GiB
 Name: VM-0-3-centos
 ID: PGIT:GW74:R5MT:AUCK:3VWO:PSBI:POWO:YATT:VC2Q:2JKN:HD4C:ALJZ
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://mirror.ccs.tencentyun.com/
 Live Restore Enabled: false

[root@VM-0-3-centos ~]#

docker help

#docker帮助命令
docker help
[root@VM-0-3-centos ~]# docker help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

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")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Build with BuildKit (Docker Inc., v0.5.1-docker)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  scan*       Docker Scan (Docker Inc.)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  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
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List 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
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  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
  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)
  search      Search the Docker Hub for images
  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
  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.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
[root@VM-0-3-centos ~]#

镜像常用命令

docker images:查看本机镜像

#语法:
docker images [OPTIONS] [REPOSITORY[:TAG]]
OPTIONS可选项作用
–all , -a显示所有图像(默认隐藏中间图像)
–digests显示摘要
–filter , -f基于所提供条件的滤波器输出
–format使用GO模板打印漂亮图像
–no-trunc不要截断输出
–quiet , -q只显示图像ID
[haokai@localhost ~]$ sudo docker images
[sudo] password for haokai:
#REPOSITORY:镜像的仓库源
#TAG:镜像的标签,版本号
#IMAGE ID:镜像的id截断后输出(整串id截取前12位)
#CREATED:镜像的创建时间
#SIZE:镜像的大小
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
tomcatv2_haokai   latest    c8ed70599b25   10 months ago   654MB
tomcat            latest    6d15a1d68603   10 months ago   649MB
mysql             latest    ab2f358b8612   10 months ago   545MB
redis             latest    ef47f3b6dc11   10 months ago   104MB
hello-world       latest    bf756fb1ae65   22 months ago   13.3kB
[haokai@localhost ~]$
#完整的镜像id信息
[haokai@localhost ~]$ sudo docker images -q --no-trunc
sha256:c8ed70599b25ecc6b90200d66d2b3d53d8a1d900eaa060b53e82572725c27c93
sha256:6d15a1d68603a32ff2bd71f02902c94b1191f1e42a2f2b3c396023c6e04d9f59
sha256:ab2f358b86124c477cc1f91066d42ca15fb2da58f029aa3c4312de5b3ca02018
sha256:ef47f3b6dc11e8f17fb39a6e46ecaf4efd47b3d374e92aeb9f2606896b751251
sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
[haokai@localhost ~]$
#TAG为latest的
[haokai@localhost ~]$ sudo docker images tomcatv2_haokai:latest
REPOSITORY        TAG       IMAGE ID       CREATED         SIZE
tomcatv2_haokai   latest    c8ed70599b25   10 months ago   654MB
[haokai@localhost ~]$

docker search:搜索镜像

OPTIONS可选项默认值作用
–filter , -f基于所提供条件的滤波器输出
–format使用格式化模板打印搜索
–limit25最大搜索结果数
–no-trunc不要截断输出

filter选项:

  • stars (int - number of stars the image has) :收藏数
  • is-automated (boolean - true or false) - is the image automated or not:是否自动化
  • is-official (boolean - true or false) - is the image official or not:是否正式版
docker search --filter stars=3 busybox
docker search --filter is-automated=true busybox
docker search --filter is-official=true --filter stars=3 busybox

format:格式化输出

可选项作用
.Name镜像名称
.Description镜像描述
.StarCount镜像的star数
.IsOfficial“确定”如果镜像是正式的
.IsAutomated“确定”,如果镜像生成是自动化的

使用–format选项,search命令将完全按照模板声明的方式输出数据。
table指令,还包括列标题,否则不包含。

#没有标题的模板,并输出Name和StarCount用冒号分隔的条目(:)前3个镜像:
[haokai@localhost ~]$ sudo docker search --format "{{.Name}}: {{.StarCount}}" redis --limit 3
redis: 10111
rediscommander/redis-commander: 67
redislabs/redisearch: 40
[haokai@localhost ~]$
#有标题的示例
[haokai@localhost ~]$ sudo docker search --format "table {{.Name}}\t{{.IsAutomated}}\t{{.IsOfficial}}" redis --limit 3
NAME                             AUTOMATED   OFFICIAL
redis                                        [OK]
rediscommander/redis-commander   [OK]
redislabs/redisearch
[haokai@localhost ~]$

docker pull:下载镜像

#语法:没有提供TAG,则Docker引擎将使用:latest标记作为默认标记
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
OPTIONS可选项默认值作用
–all-tags , -a下载存储库中的所有标记图像
–disable-content-trusttrue跳过图像验证
–platform如果服务器具有多平台能力,则设置平台
–quiet , -q抑制冗长输出

中止pull操作

杀死docker pull过程,例如通过按下CTRL-c当它在终端中运行时,将终止pull操作

联合文件系统

docker的镜像是分层的,重复的无需下载,会共用,因此可以极大的节省磁盘空间

docker rmi:删除镜像

#语法:
docker rmi [OPTIONS] IMAGE [IMAGE...]
OPTIONS可选项作用
–force , -f强力删除镜像
–no-prune不要删除未标记镜像
#删除单个镜像
docker rmi -f 镜像id1

#用$进行复合查询()内的作为参数传入
#删除全部镜像
docker rmi -f $(docker images -aq)

#删除多个镜像,空格分隔镜像id
docker rmi -f 镜像id1 镜像id2 镜像id3
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值