一、docker镜像管理
1.1、镜像搜索-search
#从docker镜像仓库模糊搜索镜像
#用法:
# docker search 镜像关键字
[root@zuolaoshi ~]# docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL
ubuntu DEPRECATED; 7720 [OK]
......以下省略
#字段说明:
NAME:镜像名称
DESCRIPTION:镜像描述
STARS:镜像星级,数字越大表示用的人越多
OFFICIAL:是否为官方 跟[OK]说明是官方
AUTOMATED: 是否为自动化构建的镜像
1.2、镜像下载-pull命令
从docker指定的仓库下载镜像到本地 用法: docker pull 镜像名称
[root@zuolaoshi ~]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
1.3、本地镜像查看-images命令
查看本地存储的镜像
[root@zuolaoshi ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest fec8bfd95b54 6 weeks ago 78.1MB
#字段说明:
REPOSITORY:镜像的名字
TAG:镜像的标签
IMAGE ID:镜像的ID号
CREATED:镜像建立时间
SIZE: 镜像大小
1.4、镜像详细信息-inspect命令
# 检查镜像信息Loaded image: ubuntu:latest信息
# 用法:docker inspect [镜像名称或者ID]
[root@zuolaoshi ~]# docker inspect ubuntu
[
{
"Id": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
"RepoTags": [
"ubuntu:latest"
],
"RepoDigests": [
"ubuntu@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177"
],
"Parent": "",
"Comment": "",
"Created": "2021-09-15T18:20:05.184694267Z",
"DockerVersion": "20.10.7",
"Author": "",
"Config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "sha256:f5b050f177fd426be8fe998a8ecf3fb1858d7e26dff4080b29a327d1bd5ba422",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20210915",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "ubuntu Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "ubuntu"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 231268856,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/38989222bbafa264d4fe4c99dd0271a72836b7ba09245ac65f70a7e99675cac4/merged",
"UpperDir": "/var/lib/docker/overlay2/38989222bbafa264d4fe4c99dd0271a72836b7ba09245ac65f70a7e99675cac4/diff",
"WorkDir": "/var/lib/docker/overlay2/38989222bbafa264d4fe4c99dd0271a72836b7ba09245ac65f70a7e99675cac4/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
1.5、镜像保存-save命令
保存镜像为压缩文件
用法: docker save -o 压缩文件名称 [镜像名称或者ID]
[root@zuolaoshi ~]# docker save -o ubuntu_base.tar ubuntu
[root@zuolaoshi ~]# ls
anaconda-ks.cfg ubuntu_base.tar init.sh
1.6、本地镜像删除-rmi命令
删除本地镜像库中的某个镜像
用法: docker rmi [镜像名称或者ID]
[root@zuolaoshi ~]# docker rmi ubuntu
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Deleted: sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6
Deleted: sha256:74ddd0ec08fa43d09f32636ba91a0a3053b02cb4627c35051aff89f853606b59
[root@zuolaoshi ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
1.7、镜像载入-load命令
导入由save保存出来的压缩文件镜像
用法: docker load -i 镜像压缩文件名称 [镜像名称或者ID]
[root@zuolaoshi ~]# docker load -i ubuntu_base.tar
74ddd0ec08fa: Loading layer 238.6MB/238.6MB
Loaded image: ubuntu:latest
1.8、镜像管理命令-image命令
镜像管理命令,和上面的命令相似
[root@zuolaoshi ~]# 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 Download an image from a registry
push Upload an image 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.
# 命令获取所有镜像的 ID
# docker images -aq
# 删除所有镜像
# docker rmi $(docker images -aq)