获取镜像
比如说我们可以这样操作
当然把这个镜像拉过来时间非常长。
查看镜像列表
命令:
docker images
说明:
使用docker images命令可以列出本地主机上已有的镜像。
信息含义:来自于哪个仓库、镜像的标签信息、镜像的ID号(唯一)、创建时间、镜像大小。
查看镜像信息
命令:
docker inspect <image_id>
说明:
docker inspect命令返回的是一个JSON的格式消息,如果我们只要其中的一项内容时,可以通过-f参数来指定。Image_id通常可以使用该镜像ID的前若干个字符组成的可区分字符串来替代完成的ID。
[root@mydocker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB [root@mydocker ~]# docker inspect 4ab4c602aa5e [ { "Id": "sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f", "RepoTags": [ "hello-world:latest" ], "RepoDigests": [ "hello-world@sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788" ], "Parent": "", "Comment": "", "Created": "2018-09-07T19:25:39.809797627Z", "Container": "15c5544a385127276a51553acb81ed24a9429f9f61d6844db1fa34f46348e420", "ContainerConfig": { "Hostname": "15c5544a3851", "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/sh", "-c", "#(nop) ", "CMD ["/hello"]" ], "ArgsEscaped": true, "Image": "sha256:9a5813f1116c2426ead0a44bbec252bfc5c3d445402cc1442ce9194fc1397027", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": {} }, "DockerVersion": "17.06.2-ce", "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": [ "/hello" ], "ArgsEscaped": true, "Image": "sha256:9a5813f1116c2426ead0a44bbec252bfc5c3d445402cc1442ce9194fc1397027", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": null }, "Architecture": "amd64", "Os": "linux", "Size": 1840, "VirtualSize": 1840, "GraphDriver": { "Data": { "RootDir": "/var/lib/docker/overlay/fe94fd635d95b02584613558345722df0ad3b787fb3050be90822e6e51b2bb0b/root" }, "Name": "overlay" }, "RootFS": { "Type": "layers", "Layers": [ "sha256:428c97da766c4c13b19088a471de6b622b038f3ae8efa10ec5a37d6d31a2df0b" ] } } ] [root@mydocker ~]#
[root@mydocker ~]# docker inspect -f {{.Os}} 4ab4c602aa5e
linux
[root@mydocker ~]#
查找镜像
比如说我们举个例子
删除镜像
[root@mydocker ~]# docker tag 4ab4c602aa5e gong/study:rest [root@mydocker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE gong/study rest 4ab4c602aa5e 8 weeks ago 1.84kB hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB [root@mydocker ~]#
还有一种情况,当我们的镜像运行在一个容器中的时候,不能直接删除镜像,可以通过加-f参数强制删除,但是非常不建议这么做!!!!
创建镜像
我们现在利用ubuntu这个容器创建一个镜像
[root@mydocker ~]# docker commit -a "gong" -m "add test.txt" e2ee7db10156 gong/test
sha256:d3ae5b7a2ce8c10e39afb074e2dc88c65b124102b214f6b3195dee05e8a67394
[root@mydocker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gong/test latest d3ae5b7a2ce8 21 seconds ago 85.8MB
ubuntu latest ea4c82dcd15a 2 weeks ago 85.8MB
hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB
[root@mydocker ~]#
迁出镜像
[root@mydocker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE gong/test latest d3ae5b7a2ce8 21 seconds ago 85.8MB ubuntu latest ea4c82dcd15a 2 weeks ago 85.8MB hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB [root@mydocker ~]# docker save -o test.tar d3ae5b7a2ce8 [root@mydocker ~]# ls anaconda-ks.cfg initial-setup-ks.cfg test.tar [root@mydocker ~]#
载入镜像
[root@mydocker ~]# docker load --input test.tar Loaded image ID: sha256:d3ae5b7a2ce8c10e39afb074e2dc88c65b124102b214f6b3195dee05e8a67394 [root@mydocker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE gong/test latest d3ae5b7a2ce8 11 minutes ago 85.8MB ubuntu latest ea4c82dcd15a 2 weeks ago 85.8MB hello-world latest 4ab4c602aa5e 8 weeks ago 1.84kB [root@mydocker ~]#
下面我对导入的这个镜像认证
[root@mydocker ~]# docker run -ti d3ae5b7a2ce8 bash root@ff2f56ca3a73:/# ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test.txt tmp usr var root@ff2f56ca3a73:/# cat test.txt hello world root@ff2f56ca3a73:/#
上传镜像
我看可以看到出问题了:denied: requested access to the resource is denied
是因为要改成docker login登录的用户名才可以
我们这样解决