docker学习-镜像常用操作命令

镜像常用的操作命令

1、查看本地所有的镜像  docker images

[root@localhost ~]# docker images  # 列出所有的镜像
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    300e315adb2f   4 months ago   209MB
[root@localhost ~]# docker images -a  # 列出所有的镜像详细信息
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    300e315adb2f   4 months ago   209MB
[root@localhost ~]# docker images -aq  # 列出所有镜像的ID
300e315adb2f

 

2、搜索镜像  docker search 镜像名

[root@localhost ~]# docker search mysql   # 搜索mysql镜像
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   10748     [OK]
mariadb                           MariaDB Server is a high performing open sou…   4047      [OK]
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   791                  [OK]
percona                           Percona Server is a fork of the MySQL relati…   533       [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   87
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   81
centurylink/mysql                 Image containing mysql. Optimized to be link…   59                   [OK]
bitnami/mysql                     Bitnami MySQL Docker Image                      50                   [OK]
databack/mysql-backup             Back up mysql databases to... anywhere!         43
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                   [OK]
prom/mysqld-exporter                                                              37                   [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   35
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   29                   [OK]
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   27
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   20
circleci/mysql                    MySQL is a widely used, open-source relation…   20
mysql/mysql-router                MySQL Router provides transparent routing be…   19
arey/mysql-client                 Run a MySQL client from a docker container      17                   [OK]
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   12                   [OK]
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offici…   3
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                    [OK]
jelastic/mysql                    An image of the MySQL database server mainta…   1
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   1                    [OK]
monasca/mysql-init                A minimal decoupled init container for mysql    0
[root@localhost ~]# docker search mysql -f=STARS=3000    # 搜索mysql镜像并加上-f参数过滤STARS大于3000
 NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 10748 [OK] mariadb MariaDB Server is a high performing open sou… 4047 [OK]

 

3、下载镜像  docker pull 镜像名【: tag】

[root@jmeter_1 ~]# docker pull tomcat # 下载Tomcat的最新版本
Using default tag: latest  
latest: Pulling from library/tomcat   # 默认下载的是最新的版本,如果加上了tag就下载对应的版本
bd8f6a7501cc: Pull complete   # 分层下载
44718e6d535d: Pull complete 
efe9738af0cb: Pull complete 
f37aabde37b8: Pull complete 
b87fc504233c: Pull complete 
8bf93eef8c9e: Pull complete 
a62c27841e77: Pull complete 
3b23560b24c9: Pull complete 
168537fce8fb: Pull complete 
6643b79f9364: Pull complete 
Digest: sha256:a655be865e9f62d6d2ed3823c7382a2d77d0a034eb17714bbf2a514c3f620717   # 签名
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest   # 下载的真实地址

docker pull tomcat == docker pull docker.io/library/tomcat:latest

 

 4、删除镜像  docker rmi -f 镜像id

[root@jmeter_1 ~]# docker images    #查看本地所有的镜像
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
tomcat        latest    bd431ca8553c   4 days ago    667MB
hello-world   latest    d1165f221234   5 weeks ago   13.3kB
[root@jmeter_1 ~]# docker rmi -f d1165f221234   # 删除镜像
Untagged: hello-world:latest
Untagged: hello-world@sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
[root@jmeter_1 ~]# docker images   # 再次查看镜像发现hello-world镜像被删除
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
tomcat       latest    bd431ca8553c   4 days ago   667MB
[root@jmeter_1 ~]# docker pull hello-world   # 下载hello-world镜像
Using default tag: latest
latest: Pulling from library/hello-world
b8dfde127a29: Already exists 
Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
[root@jmeter_1 ~]# docker images  # 查看所有镜像
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
tomcat        latest    bd431ca8553c   4 days ago    667MB
hello-world   latest    d1165f221234   5 weeks ago   13.3kB
[root@jmeter_1 ~]# docker rmi -f $(docker images -aq)   # 删除所有的镜像
Untagged: tomcat:latest
Untagged: tomcat@sha256:a655be865e9f62d6d2ed3823c7382a2d77d0a034eb17714bbf2a514c3f620717
Deleted: sha256:bd431ca8553c039385c45897de8b5e8db84186a8be36204c5c5c5cf5afdb92df
Deleted: sha256:3fc88da1196bfb79353e2fdda2723bcc2c8663b550156e05860c4e5e4818e790
Deleted: sha256:81cfd81a14bcd229a5cd6cfbcde7f3716f17c7c2616fae5b02ee4e52f303895d
Deleted: sha256:99d83ae0416a02d6333e941caa76b62d482d51aae7bdd56441f74c7fde67d832
Deleted: sha256:1edac5c7987e3199aac18d076089231c9d5e2bdb6dae7ed70cc3048a9d04d694
Deleted: sha256:d8b838beea6f90d6556650b670930f58d16bf0007b1a7d9effe3dd1735fdfa8d
Deleted: sha256:3f61a2fb8ca663bf88786884ba5f5be3274c91ee82c1ae9bb36bb1ad1fa0b3d0
Deleted: sha256:ac996dca9c2f86e5d2744187de88cd328f12dde417a7950dff33448906228ae3
Deleted: sha256:e4ed057c6550560fb44b9146dadd5c62bfc00404ba69937c89a44e10485c9010
Deleted: sha256:985d0a2cd810a6fc7b68886aee94ee060acd63e122a1def04370dac5fa9d05f6
Deleted: sha256:e2c6ff46235709f5178ab7c1939f4fba7237ffde84e13b1582fa5f0837c1d978
Untagged: hello-world:latest
Untagged: hello-world@sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
[root@jmeter_1 ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

 

posted @ 2021-04-15 23:25  大渝  阅读(495)  评论(0编辑  收藏  举报