Docker基础系列-3.docker服务命令与镜像命令

3.1 docker服务命令

## 启动docker
systemctl start docker
## 停止docker
systemctl stop docker
## 重启docker
systemctl restart docker
## 查看docker状态
systemctl status docker
## 开机启动
systemctl enable docker
## 查看docker概要信息
docker info
## 查看docker帮助文档
docker--help

3.2 docker镜像命令

搜索镜像

## 搜索镜像
## 语法
docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
      
##     
docker search 镜像名
##例如
docker search redis
NAME                                        DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
redis                                       Redis is an open source key-value store that…   11198               [OK]                
bitnami/redis                               Bitnami Redis Docker Image                      227                                     [OK]
bitnami/redis-sentinel                      Bitnami Docker Image for Redis Sentinel         39                                      [OK]
bitnami/redis-cluster                                                                       34                                      

拉取镜像

## 语法
docker pull [OPTIONS] NAME[:TAG|@DIGEST]

Pull an image or a repository from a registry

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
 docker pull [选项] [Docker Registey 地址[:端口号]/] 镜像名[:标签]     
 
 ## 例如
 docker pull centos:centos7.9.2009

查看本地镜像

## 语法
docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

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 numeric IDs
  
## 例如
docker images   
## 等同于docker image ls
docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              feb5d9fea6a5        10 months ago       13.3kB
centos              centos7.9.2009      eeb6ee3f44bd        10 months ago       204MB
  • REPOSITORY:仓库及镜像名称
  • TAG:标签及版本号
  • IMAGE ID:镜像ID,镜像的唯一标识
  • CREATED:该镜像的构建时间
  • SIZE: 该镜像文件的大小

删除本地镜像

## 语法
## 可以使用 镜像ID、镜像名作为镜像的唯一标识删除镜像。
docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

Options:
  -f, --force      Force removal of the image
      --no-prune   Do not delete untagged parents
## 常用的[选项]是 -f 表示强制删除
## 有的时候同一个镜像上传到多个仓库,此时镜像ID就不再是唯一标识,需要使用 -f 强制删除才能删除镜像(具有同一个镜像ID的所有本地镜像全部删除)。 
      
## 例如
docker rmi centos
## 删除全部
docker rmi -f ${docker images-qa}

虚悬镜像

在镜像列表中,可能会存在一种特殊的镜像,该镜像既没有仓库名/镜像名称,也没有标签/版本号,这两个位置均显示 <none> ,这种镜像通常被称为 虚悬镜像

虚悬镜像产生的原因是什么?

其实虚悬镜像最开始pull下载的时候是有镜像名称和标签版本号名称的,比如redis官方发布了一个docker镜像6.0版本,过了一段时间发现6.0版本的镜像有可能存在安全问题,所以重新构建了一个6.0版本的镜像。

镜像名称redis和6.0的TAG都被新发布的镜像占用了,旧版本的镜像就丢失了镜像名称和标签,变成了虚悬镜像。

一般来说,虚悬镜像已经失去了存在的价值,是可以随意删除的,使用下面的命令删除

docker image prune

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

[root@localhost ~]# docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              3                   1                   276.7MB             276.7MB (99%)
Containers          1                   0                   0B                  0B
Local Volumes       0                   0                   0B                  0B
Build Cache                                                 0B                  0B
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值