1. 下載與查看鏡像:
[root@centos_7_1]:[~]# docker search alpine
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
alpine A minimal Docker image based on Alpine Linux… 4598 [OK]
mhart/alpine-node Minimal Node.js built on Alpine Linux 401
anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.28 over A… 368 [OK]
#-----------------------------分割線,篇幅有限厂僧,中間已省略-----------------------------
spotify/alpine Alpine image with `bash` and `curl`. 5 [OK]
functions/alpine Alpine Linux / BusyBox with the OpenFaaS wat… 4
govuk/gemstash-alpine Gemstash server running on Alpine 3 [OK]
smartentry/alpine alpine with smartentry 0
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image pull alpine:3.8
3.8: Pulling from library/alpine
4fe2ade4980c: Pull complete
Digest: sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Status: Downloaded newer image for alpine:3.8
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine 3.8 196d12cf6ab1 2 months ago 4.41MB
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image ls --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine 3.8 sha256:196d12cf6ab19273823e700516e98eb1910b03b17840f9d5509f03858484d321 2 months ago 4.41MB
上述命令詳細(xì)說(shuō)明:
- docker search alpine
- 查看互聯(lián)網(wǎng)遠(yuǎn)程倉(cāng)庫(kù)中的apine所有鏡像寝姿。
- docker image ls
- 列出本地主機(jī)鏡像
- Linux中的ls命令通用與Docker容器中
- docker image pull alpine:3.8
- 從互聯(lián)網(wǎng)上的Registry倉(cāng)庫(kù)下載Docker鏡像,必須確認(rèn)哄孤,已設(shè)置Docker鏡像加速,如阿里云的鏡像加速。
- alpine:3.8 鏡像格式說(shuō)明:鏡像名:標(biāo)簽
- 顯示鏡像時(shí)缔俄,顯示各種屬性的含義:
- REPOSITORY 鏡像所屬倉(cāng)庫(kù)
- TAG 鏡像標(biāo)簽
- IMAGE ID 鏡像ID(每個(gè)鏡像都有一個(gè)標(biāo)識(shí)符)
- CREATED 鏡像創(chuàng)建時(shí)間
- SIZE 鏡像大小
- docker image ls --no-trunc
- 這里顯示完整image ID,如不加--no-trunc器躏,則默認(rèn)顯示簡(jiǎn)寫(xiě)ID俐载。
- docker image ls --digests
- 查看 image(鏡像)的完整的哈希值:
2. 鏡像文件的標(biāo)簽TAG
- 鏡像文件可以不加標(biāo)簽,默認(rèn)是最新版本登失,如:
[root@centos_7_1]:[~]# docker image pull alpine
Using default tag: latest # 不加標(biāo)簽的情況下遏佣,默認(rèn)標(biāo)簽為:latest
latest: Pulling from library/alpine
Digest: sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Status: Downloaded newer image for alpine:latest
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine 3.8 196d12cf6ab1 2 months ago 4.41MB
alpine latest 196d12cf6ab1 2 months ago 4.41MB
- 在上述案例中,可以看到鏡像的ID(IMAGE ID)揽浙;
- 表示這兩個(gè)鏡像文件其實(shí)是一個(gè)文件状婶;
- 只是用兩個(gè)標(biāo)簽顯示,而且下載第二個(gè)文件時(shí)速度特別快馅巷;
- 這代表系統(tǒng)命令執(zhí)行時(shí)膛虫,會(huì)掃碼本地鏡像文件,與互聯(lián)網(wǎng)文件作對(duì)比钓猬,如果本地存在稍刀,只是做加標(biāo)簽處理。
- 如果下載鏡像時(shí)不注明標(biāo)簽敞曹,則默認(rèn)下載最新版账月。
- 最新版默認(rèn)標(biāo)簽為:latest综膀。
3. 刪除鏡像:
[root@centos_7_1]:[~]# docker image rm alpine:3.8
Untagged: alpine:3.8
[root@centos_7_1]:[~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 196d12cf6ab1 2 months ago 4.41MB
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image rm alpine:latest
Untagged: alpine:latest
Untagged: alpine@sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Deleted: sha256:196d12cf6ab19273823e700516e98eb1910b03b17840f9d5509f03858484d321
Deleted: sha256:df64d3292fd6194b7865d7326af5255db6d81e9df29f48adde61a918fbd8c332
[root@centos_7_1]:[~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
- 刪除鏡像時(shí),加標(biāo)簽局齿,則刪除相應(yīng)標(biāo)簽的鏡像文件僧须;
- 如果不加標(biāo)簽,默認(rèn)刪除標(biāo)簽為latest的鏡像文件项炼;
- 如果一個(gè)鏡像文件有多個(gè)標(biāo)簽担平;
- 則刪除最后一個(gè)標(biāo)簽時(shí),才是真正刪除了鏡像文件锭部,以前的刪除只是刪除了標(biāo)簽而已暂论。
4. 鏡像的詳細(xì)信息(元數(shù)據(jù))
[root@centos_7_1]:[~]# docker image pull alpine:3.8
3.8: Pulling from library/alpine
4fe2ade4980c: Already exists
Digest: sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528
Status: Downloaded newer image for alpine:3.8
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image inspect alpine:3.8
[
{
"Id": "sha256:196d12cf6ab19273823e700516e98eb1910b03b17840f9d5509f03858484d321",
"RepoTags": [
"alpine:3.8"
],
"RepoDigests": [
"alpine@sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528"
],
#-----------------------------分割線,篇幅有限,中間已省略-----------------------------
上述命令詳細(xì)說(shuō)明
- docker image pull alpine:3.8
- inspect命令:顯示鏡像的詳細(xì)信息(鏡像的元數(shù)據(jù))拌禾。
- 這里需要特別說(shuō)明中間的一段代碼:
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/bin/sh\"]"
],
- 這段代碼表示:以這個(gè)鏡像創(chuàng)建的容器取胎,容器啟動(dòng)時(shí)默認(rèn)啟動(dòng)的應(yīng)用進(jìn)程為/bin/sh。
5. Docker鏡像命令的所有子命令
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image ls --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
alpine 3.8 sha256:621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528 196d12cf6ab1 2 months ago 4.41MB
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image ls --help
Usage: docker image ls [OPTIONS] [REPOSITORY[:TAG]]
List images
Aliases:
ls, images, list
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
#-----------------------------分割線-----------------------------
[root@centos_7_1]:[~]# docker image --help
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.
- docker image ls --help
- 查看關(guān)于docker鏡像命令中子命令ls的詳細(xì)使用方法
- docker image --help
- 顯示所有Docker鏡像的所有子命令
6. Docker新版本與老版本命令對(duì)比
[root@centos_7_1]:[~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine 3.8 196d12cf6ab1 2 months ago 4.41MB
[root@centos_7_1]:[~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine 3.8 196d12cf6ab1 2 months ago 4.41MB
- Docker鏡像命令:
- 老版本:
- docker images
- 新版本:
- docker images
Docker分類(lèi)---文章目錄:
- docker images
- 老版本:
第一章 初識(shí)Docker | 點(diǎn)擊此處
第二章 安裝Docker以及簡(jiǎn)單配置 | 點(diǎn)擊此處
第三章 Docker容器的生命周期 | 點(diǎn)擊此處
第四章 Docker命令匯總 | 點(diǎn)擊此處
第五章 Docker基礎(chǔ)命令詳解 | 點(diǎn)擊此處
第六章 Docker---鏡像的命令詳解 | 點(diǎn)擊此處
第七章 Docker---容器的命令詳解 | 點(diǎn)擊此處
第八章 Docker與Alpine不解之緣 | 點(diǎn)擊此處
未完待續(xù)