docker–鏡像操作

  • 2019 年 11 月 25 日
  • 筆記

5 docker 鏡像操作

Docker 鏡像是容器的基礎。鏡像是一個有序集合,其中包含根文件系統更改和在容器運 行時中使用的相應執行參數。鏡像通常 包含堆疊在彼此之上的聯合分層文件系統。鏡像 沒有狀態並且始終不會發生更改。 當運行容器時,使用的鏡像如果在本地中不存在, docker 就會自動從 docker 鏡像倉庫中下載,默認是從 Docker Hub 公共鏡像源下載。

5.1 列出鏡像

docker images  REPOSITORY          TAG                 IMAGE ID            CREATED        SIZE  hello‐world         latest              fce289e99eb9        5 months ago         1.84kB  這些鏡像都是存儲在Docker宿主機的/var/lib/docker目錄下。
  • REPOSITORY :表示鏡像的倉庫源
  • TAG :鏡像的標籤(版本),同一倉庫源可以有多個 TAG,代表這個倉庫源的不同 個版本,如ubuntu倉庫源里,有15.10、14.04等多個不同的版本。
  • IMAGE ID :鏡像ID
  • CREATED :鏡像創建時間
  • SIZE :鏡像大小

5.2 查找鏡像 –docker search 鏡像名稱

[root@docker1 ~]# docker search centos  NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED  centos                             The official build of CentOS.                   5685                [OK]  ansible/centos7-ansible            Ansible on Centos7                              125                                     [OK]  jdeathe/centos-ssh                 OpenSSH / Supervisor / EPEL/IUS/SCL Repos - …   114                                     [OK]  consol/centos-xfce-vnc             Centos container with "headless" VNC session…   100                                     [OK]  centos/mysql-57-centos7            MySQL 5.7 SQL database server                   64  imagine10255/centos6-lnmp-php56    centos6-lnmp-php56                              57                                      [OK]  tutum/centos                       Simple CentOS docker image with SSH access      44  centos/postgresql-96-centos7       PostgreSQL is an advanced Object-Relational …   39  kinogmt/centos-ssh                 CentOS with SSH                                 29                                      [OK]  pivotaldata/centos-gpdb-dev        CentOS image for GPDB development. Tag names…   10  guyton/centos6                     From official centos6 container with full up…   9                                       [OK]  nathonfowlie/centos-jre            Latest CentOS image with the JRE pre-install…   8                                       [OK]  drecom/centos-ruby                 centos ruby                                     6                                       [OK]  darksheer/centos                   Base Centos Image -- Updated hourly             3                                       [OK]  mamohr/centos-java                 Oracle Java 8 Docker image based on Centos 7    3                                       [OK]  pivotaldata/centos                 Base centos, freshened up a little with a Do…   3  pivotaldata/centos-mingw           Using the mingw toolchain to cross-compile t…   2  miko2u/centos6                     CentOS6 日本語環境                                   2                                       [OK]  pivotaldata/centos-gcc-toolchain   CentOS with a toolchain, but unaffiliated wi…   2  indigo/centos-maven                Vanilla CentOS 7 with Oracle Java Developmen…   1                                       [OK]  mcnaughton/centos-base             centos base image                               1                                       [OK]  blacklabelops/centos               CentOS Base Image! Built and Updates Daily!     1                                       [OK]  pivotaldata/centos6.8-dev          CentosOS 6.8 image for GPDB development         0  pivotaldata/centos7-dev            CentosOS 7 image for GPDB development           0  smartentry/centos                  centos with smartentry                          0                                       [OK]  ​
  • NAME :鏡像倉庫源的名稱
  • DESCRIPTION:鏡像的描述
  • starts:用戶評價,反應一個鏡像的受歡迎程度
  • OFFICIAL:是否docker官方發布
  • auto commit:自動構建,表示該鏡像由Docker Hub自動構建流程創建的

5.3 拉取鏡像

docker pull 鏡像名稱[:version]

Docker鏡像首頁,包括官方鏡像和其它公開鏡像。Docker Hub上最受歡迎的10大鏡像 (通過Docker registry API獲取不了鏡像被pull的個數,只能通過鏡像的stars數量,來衡 量鏡像的流行度。毫無疑問,擁有最高stars數量的庫都是官方庫。國情的原因,中國下 載 Docker HUB 官方的相關鏡像比較慢,可以使用中國(docker.io)的一些鏡像加速 器,鏡像保持和官方一致,關鍵是速度塊,推薦使用。

配置鏡像加速器:

PS:配置鏡像加速器(參考該網站具體的文檔操作)  ‐ 阿里雲(先加入阿里雲開發者平台:https://dev.aliyun.com)  ‐ docker中國加速器(https://www.docker‐cn.com)  ‐ USTC加速器(https://lug.ustc.edu.cn/wiki/ )  真正的公共服務(無需任何操  作)  ‐ daocloud、網易蜂巢加速器:略  步驟:  sudo vim /etc/docker/daemon.json  配置內容:  {     "registry‐mirrors": ["https://cs913o6k.mirror.aliyuncs.com"]  }  sudo systemctl daemon‐reload  sudo systemctl restart docker
Error1:在拉取鏡像時候,出現如下錯誤,可以配置鏡像加速器
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

5.4 刪除鏡像

1、刪除一個鏡像  docker rmi 鏡像名稱/id  2、刪除多個鏡像  docker rmi 鏡像名稱1/id1 鏡像名稱2/id2 ...  3、刪除所有鏡像  docker rmi `docker images ‐q`