Docker镜像管理

柳三千

文章最后更新时间:2022年10月20日已超过771天没有更新。

一、在镜像仓查询镜像文件(OFFICIAL代表官方认证)

#查询mysql镜像文件
[root@localhost ~]# docker search mysql
NAME                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                           MySQL is a widely used, open-source relation…   13346     [OK]       
mariadb                         MariaDB Server is a high performing open sou…   5098      [OK]       
phpmyadmin                      phpMyAdmin - A web interface for MySQL and M…   657       [OK]       
percona                         Percona Server is a fork of the MySQL relati…   592       [OK]       
bitnami/mysql                   Bitnami MySQL Docker Image                      78                   [OK]
databack/mysql-backup           Back up mysql databases to... anywhere!         70
#查询mysql镜像文件
[root@localhost ~]# docker search nginx
NAME                                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx                                             Official build of Nginx.                        17538     [OK]       
linuxserver/nginx                                 An Nginx container, brought to you by LinuxS…   178                  
bitnami/nginx                                     Bitnami nginx Docker Image                      141                  [OK]
ubuntu/nginx                                      Nginx, a high-performance reverse proxy & we…   63                   
bitnami/nginx-ingress-controller                  Bitnami Docker Image for NGINX Ingress Contr…   20                   [OK]
rancher/nginx-ingress-controller                                                                  11                   
webdevops/nginx                                   Nginx container                                 10                   [OK]
#查看centos镜像文件
[root@localhost ~]# docker search centos
NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                       DEPRECATED; The official build of CentOS.       7361      [OK]       
kasmweb/centos-7-desktop                     CentOS 7 desktop for Kasm Workspaces            25                   
couchbase/centos7-systemd                    centos7-systemd images with additional debug…   5                    [OK]
dokken/centos-7                              CentOS 7 image for kitchen-dokken               3

              

二、下载镜像文件

[root@localhost ~]# docker search ubuntu
NAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                           Ubuntu is a Debian-based Linux operating sys…   15096     [OK]       
websphere-liberty                WebSphere Liberty multi-architecture images …   290       [OK]
#拉取ubuntu镜像文件
[root@localhost ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
cf92e523b49e: Pull complete 
Digest: sha256:35fb073f9e56eb84041b0745cb714eff0f7b225ea9e024f703cab56aaa5c7720
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest


三、查看本地镜像文件

root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    51086ed63d8c   13 days ago   142MB
ubuntu       latest    216c552ea5ba   2 weeks ago   77.8MB


四、删除镜像文件

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    51086ed63d8c   13 days ago   142MB
ubuntu       latest    216c552ea5ba   2 weeks ago   77.8M
#查看容器使用的记录
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS                      PORTS     NAMES
b507de224c8f   nginx     "/docker-entrypoint.…"   18 minutes ago   Exited (0) 16 minutes ago             jovial_blackwell

#删除容器使用记录
[root@localhost ~]# docker rm b507de224c8f
b507de224c8f
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
#再次删除nginx镜像
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    51086ed63d8c   13 days ago   142MB

[root@localhost ~]# docker rmi 51086ed63d8c
Untagged: nginx:latest
Untagged: nginx@sha256:2f770d2fe27bc85f68fd7fe6a63900ef7076bc703022fe81b980377fe3d27b70
Deleted: sha256:51086ed63d8cba3a6a3d94ecd103e9638b4cb8533bb896caf2cda04fb79b862f
Deleted: sha256:c22f011a5c63a718e3155ef21b930f5583102384c8e333299913ed660baa230c
Deleted: sha256:1235ee8acd48a34c389280d8192ae79ef241d546eeea2f3416b64608d68d8538
Deleted: sha256:80ab7667b1007f2ed4b5387e7585e18d3ca1899c76449240e2890373a8e77285
Deleted: sha256:4833b18722fc3d06feafaa0f61726b1b11baa1daa0ea455e6e2ab66a7c8db283
Deleted: sha256:98b8d2ed046082a8f6c2fb2f34430f5142fea7a7078326d980b323d71640d8ff
Deleted: sha256:fe7b1e9bf7922fbc22281bcc6b4f5ac8f1a7b4278929880940978c42fc9d0229

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
#这个未曾使用的镜像,可以直接删除
[root@localhost ~]# docker rmi 216c552ea5ba
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:35fb073f9e56eb84041b0745cb714eff0f7b225ea9e024f703cab56aaa5c7720
Deleted: sha256:216c552ea5ba7b0e3f6e33624e129981c39996021403518019d19b8843c27cbc
Deleted: sha256:17f623af01e277c5ffe6779af8164907de02d9af7a0e161662fc735dd64f117b

[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        latest    51086ed63d8c   13 days ago   142MB
#删除多个
docker rmi -f 镜像名1  镜像名2
#删除全部
docker rmi -f $(docker images -qa)


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

docker system df
文章版权声明:除非注明,否则均为柳三千运维录原创文章,转载或复制请以超链接形式并注明出处。

目录[+]

取消
微信二维码
微信二维码
支付宝二维码