docker images 是docker的三大组件之一。 docker把下载的 images 存储到docker主机上,如果一个 image 不在主机上,docker会从一个镜像仓库下载,默认的仓库是 DOCKER HUB 公共仓库。
docker images 的内容,包括: • 使用和管理本地主机上的 images • 创建一个基础的 images • 上传 images 到
docker hub (公共images仓库) • 列出本地主机上已经存在的 images
使用docker images 显示本机上的images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
REPOSITORY:来自于哪个仓库
TAG:可以说是版本
IMAGE ID:镜像的ID号
CREATED:创建的时间
SIZE:镜像的大小
下载images
[root@localhost ~]# docker pull nginx
查看一下images
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 605c77e624dd 17 months ago 141MB
当我们不知道版本的时候可以查找
[root@localhost ~]# docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 18576 [OK]
unit Official build of NGINX Unit: Universal Web … 5 [OK]
nginxproxy/nginx-proxy Automated Nginx reverse proxy for docker con… 87
nginxproxy/acme-companion Automated ACME SSL certificate generation fo… 113
bitnami/nginx Bitnami nginx Docker Image 164 [OK]
bitnami/nginx-ingress-controller Bitnami Docker Image for NGINX Ingress Contr… 29 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 95
nginxproxy/docker-gen Generate files from docker container meta-da… 12
kasmweb/nginx An Nginx image based off nginx:alpine and in… 6
rancher/nginx-ingress-controller 11
rancher/nginx-ingress-controller-defaultbackend 2
bitnami/nginx-exporter 3
rancher/nginx 2
rapidfort/nginx-ib RapidFort optimized, hardened image for NGIN… 10
rapidfort/nginx RapidFort optimized, hardened image for NGINX 14
vmware/nginx-photon 1
查看镜像的详细信息
[root@localhost ~]# docker inspect nginx
[
{
"Id": "sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85",
"RepoTags": [
"192.168.8.10:5000/nginx:latest",
"nginx:latest"
],
"RepoDigests": [
"192.168.8.10:5000/nginx@sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3",
"nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31"
],
"Parent": "",
"Comment": "",
"Created": "2021-12-29T19:28:29.892199479Z",
"Container": "ca3e48389f7160bc9d9a892d316fcbba459344ee3679998739b1c3cd8e56f7da",
"ContainerConfig": {
"Hostname": "ca3e48389f71",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.21.5",
"NJS_VERSION=0.7.1",
"PKG_RELEASE=1~bullseye"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"nginx\" \"-g\" \"daemon off;\"]"
],
"Image": "sha256:82941edee2f4d17c55563bb926387c3ae39fa1a99777f088bc9d3db885192209",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/docker-entrypoint.sh"
],
......
查看镜像的完整ID
[root@localhost ~]# docker images --no-trunc
REPOSITORY TAG IMAGE ID CREATED SIZE
启动一个容器
[root@localhost ~]# docker run -i -t centos:7 /bin/bash
[root@05a43144951c /]#
进到容器里这个主机名是以ID的名称来命名的
上传镜像
可以通过docker push命令,把自己创建的镜像上传到仓库中来共享,用户需要在Dokcer hub上完成注册后,可以推送自己的镜像到仓库中。有两种访问可以创建和注册一个Docker hub账户:1.通过网站(https://hub.docker.com)2.可以使用命令行输入docker login命令来创建一个Docker hub账号
[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: mlqi
Password:
邮箱确认 一旦你填写完毕表格,请查看你的电子邮件,通过点击欢迎信息中的链接来激活您的账户。
然后我们在公有的仓库里创建一个仓库
创建完成之后会有命令的提示,根据提示把需要上传的镜像改名
[root@localhost ~]# docker tag nginx:latest mlqi/web:v1
然后在把更改好的镜像上传
[root@localhost ~]# docker push mlqi/web:v1
rmi移除本地images
[root@localhost ~]# docker rmi nginx
当需要把一台机器上的镜像迁移到另一台机器的时候,需要存出镜像与载入镜像
使用docker save命令把镜像保存到本地
[root@localhost ~]# docker save -o nginx.tar.gz nginx:latest
然后载入镜像可以使用docker load导入
[root@localhost ~]# docker load -i nginx.tar.gz
或者可以
[root@localhost ~]# docker load < nginx.tar.gz