當(dāng)運行容器時粒梦,使用的鏡像如果在本地中不存在南誊,docker 就會自動從 docker 鏡像倉庫中下載咒唆,默認(rèn)是從 Docker Hub 公共鏡像源下載硼补。我們可以從 Docker Hub 網(wǎng)站來搜索鏡像冒嫡,Docker Hub 網(wǎng)址為: https://hub.docker.com/拇勃,我們也可以使用 docker search 命令來搜索鏡像。比如我們需要一個centos的鏡像來作為我們的服務(wù)器孝凌。我們可以通過 docker search 命令搜索 centos 來尋找適合我們的鏡像方咆。
搜索鏡像:docker search
選鏡像的建議: 1.優(yōu)先考慮官方 2.stars數(shù)量多
[root@docker01 ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 5461 [OK]
ansible/centos7-ansible Ansible on Centos7 122 [OK]
jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.6.1810 x86… 110 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 93 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 59
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 … 38
kinogmt/centos-ssh CentOS with SSH 28 [OK]
centos/php-56-centos7 Platform for building and running PHP 5.6 ap… 21
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 10
guyton/centos6 From official centos6 container with full up… 9 [OK]
drecom/centos-ruby centos ruby 6 [OK]
mamohr/centos-java Oracle Java 8 Docker image based on Centos 7 3 [OK]
darksheer/centos Base Centos Image -- Updated hourly 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 日本語環(huán)境 2 [OK]
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 2
mcnaughton/centos-base centos base image 1 [OK]
indigo/centos-maven Vanilla CentOS 7 with Oracle Java Developmen… 1 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
pivotaldata/centos7-dev CentosOS 7 image for GPDB development 0
smartentry/centos centos with smartentry 0 [OK]
pivotaldata/centos6.8-dev CentosOS 6.8 image for GPDB development 0
[root@docker01 ~]#
= Name:鏡像名稱,
= DESCRIPTION:鏡像的描述
= STARS:別星標(biāo)的數(shù)量蟀架,數(shù)量越大說明受人認(rèn)可度越高
= OFFICIAL:是否為官方產(chǎn)品
= AUTOMATED:是否為自動化構(gòu)建
獲取鏡像: docker pull(push)
(因為墻的原因峻呛,需要鏡像加速,否則連接超時辜窑,無法下載)
鏡像加速器:阿里云加速器钩述,daocloud加速器,中科大加速器穆碎,Docker 中國官方鏡像加速:https://registry.docker-cn.com
docker pull centos:6.8(沒有指定版本牙勘,默認(rèn)會下載最新版)
docker pull daocloud.io/huangzhichong/alpine-cn:latest
[root@docker01 ~]# docker pull centos:6.8
6.8: Pulling from library/centos
7ce0cebb9dca: Pull complete
Digest: sha256:39abd0c8e375de6fb7334d42ec2a46643f34cbc1bbaf37e2b484065f05eaa7a2
Status: Downloaded newer image for centos:6.8
[root@docker01 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
8ba884070f61: Pull complete
Digest: sha256:a799dd8a2ded4a83484bbae769d97655392b3f86533ceb7dd96bbac929809f3c
Status: Downloaded newer image for centos:latest
[root@docker01 ~]#
擴展:查詢docker鏡像所有版本https://hub.docker.com/r/library/
國內(nèi)是所有鏡像網(wǎng)站:https://www.douban.com/note/517555410/
私有倉庫的鏡像名稱都較長(網(wǎng)站地址,用戶名所禀,版本名等)
docker鏡像其他操作
1.查看鏡像:docker images(等效命令:docker image ls)
[root@docker01 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 98ebf73aba75 5 days ago 109MB
centos 6.8 82f3b5f3c58f 4 months ago 195MB
centos latest 9f38484d220f 4 months ago 202MB
[root@docker01 ~]#
[root@docker01 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 98ebf73aba75 5 days ago 109MB
centos 6.8 82f3b5f3c58f 4 months ago 195MB
centos latest 9f38484d220f 4 months ago 202MB
[root@docker01 ~]#
REPOSITORY:鏡像名字
TAG:標(biāo)簽(可自定義)
IMAGE ID:鏡像ID(唯一)
CREATED:創(chuàng)建時間
SIZE:鏡像大小
2.刪除鏡像 docker rmi 等效命令(docker image rm) 例子:docker image rm centos:latest
[root@docker01 ~]# docker rmi centos:6
Untagged: centos:6
Untagged: centos@sha256:dec8f471302de43f4cfcf82f56d99a5227b5ea1aa6d02fa56344986e1f4610e7
Deleted: sha256:d0957ffdf8a2ea8c8925903862b65a1b6850dbb019f88d45e927d3d5a3fa0c31
Deleted: sha256:af6bf1987c2eb07d73f33836b0d8fd825d7c785273526b077e46780e8b4b2ae9
[root@docker01 ~]#
[root@docker01 ~]# docker image rm centos:latest
Untagged: centos:latest
Untagged: centos@sha256:a799dd8a2ded4a83484bbae769d97655392b3f86533ceb7dd96bbac929809f3c
Deleted: sha256:9f38484d220fa527b1fb19747638497179500a1bed8bf0498eb788229229e6e1
Deleted: sha256:d69483a6face4499acb974449d1303591fcbb5cdce5420f36f8a6607bda11854
[root@docker01 ~]#
= docker rmi centos:6方面,需要在所刪容器后加上標(biāo)簽,否則(docker rmi centos)默認(rèn)刪掉最新版
3.導(dǎo)出鏡像 docker save 等效命令(docker image save) 例子:docker image save centos > docker-centos7.4.tar.gz
[root@docker01 ~]# docker image save centos:6.8 >docker_centos6.8.tar.gz
[root@docker01 ~]# ll
total 197480
-rw-------. 1 root root 1757 Nov 27 2018 anaconda-ks.cfg
-rw-r--r-- 1 root root 202213376 Jul 23 09:36 docker_centos6.8.tar.gz
[root@docker01 ~]#
4.導(dǎo)入鏡像 docker load 等效命令(docker image load)例子:docker image load -i docker-centos7.4.tar.gz
[root@docker01 ~]# docker image load -i docker_centos6.8.tar.gz
ad337ac82f03: Loading layer [==================================================>] 202.2MB/202.2MB
Loaded image: centos:6.8
-i:指定導(dǎo)入的鏡像
5.docker其他命令色徘,通過docker image可查看其他docker命令
[root@docker01 ~]# docker image
Usage: docker image COMMAND
Manage images
Commands:
build Build an image from a Dockerfile
history Show the history of an image
import Import the contents from a tarball to create a filesystem image
inspect Display detailed information on one or more images
load Load an image from a tar archive or STDIN
ls List images
prune Remove unused images
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rm Remove one or more images
save Save one or more images to a tar archive (streamed to STDOUT by default)
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Run 'docker image COMMAND --help' for more information on a command.
[root@docker01 ~]#
= build:構(gòu)建鏡像恭金,可手動創(chuàng)建鏡像
= history:查看構(gòu)建鏡像的歷史記錄
= import:導(dǎo)入鏡像(已棄用)
= inspect:查看鏡像詳情信息,屬性
= load:導(dǎo)入鏡像
= ls:查看鏡像列表
= prune:刪除鏡像(已棄用)
= pull:下載鏡像
= push:上傳鏡像
= rm:刪除鏡像
= save:導(dǎo)出鏡像
= tag:給鏡像取別名