DOCKER学习_009:Docker的镜像管理
1 查看镜像
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 e263c3a3ce1f days ago .2MB
httpd 2.4 c2aa7e16edd8 days ago 165MB
centos 5e35e350aded weeks ago 203MB
nginx latest 540a289bab6c months ago 126MB
goodsmileduck/redis-cli latest 4b2315bf1ad2 months ago .9MB
镜像的SIZE的是压缩后的大小,实际运行后的大小,要比这个SIZE大
2 镜像命名规范
无论我们对镜像做何种操作,首先它得有个名字。我们在前面使用docker run来运行容器的时候,就需要传递一个镜像名称,容器基于该镜像来运行。
一个完整的镜像名称由两部分组成:
<image name> = <repository>:[tag]
其中repository包含如下内容:
[Docker Registry地址/][项目目录/]<名称>
所以一个完整的镜像命名如下:
[Docker Registry地址/][项目目录/]<名称>:[标签]
当没指明镜像tag时,默认为latest,但latest没有任何特殊含义,在docker hub上很多repository将latest作为最新稳定版本的别名,但这只是一种约定,不是强制规定,一个repository可以有多个tag,而多个tag也可能对应同一个镜像
3 镜像的基本操作
拉取镜像
docker pull 镜像名,默认是从dokcer的仓库中拉取
[root@docker-server3 ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
也可以指定位置拉取镜像
[root@docker-server3 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.1.3
- 指定仓库位置 registry.cn-hangzhou.aliyuncs.com
- 路径:google_containers
- 镜像名:coredns:1.1.3
1.1.: Pulling from google_containers/coredns
88286f41530e: Pull complete
9e8fb813cddc: Pull complete
3ac8c130be3b: Pull complete
Digest: sha256:d929e48a87979279307111fd28a52272d3fac0ed1dc8f2f53a9489be45e5f2eb
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.1.
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.1.
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 e263c3a3ce1f days ago .2MB
httpd 2.4 c2aa7e16edd8 days ago 165MB
centos 5e35e350aded weeks ago 203MB
nginx latest 540a289bab6c months ago 126MB
centos latest 0f3e07c0138f months ago 220MB
goodsmileduck/redis-cli latest 4b2315bf1ad2 months ago .9MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.1. b3b94275d97c months ago .6MB
4 获取镜像的详细信息
[root@docker-server3 ~]# docker inspect centos:latest
[
{
"Id": "sha256:0f3e07c0138fbe05abcb7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da",
"RepoTags": [
"centos:latest"
],
"RepoDigests": [
"centos@sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9"
],
"Parent": "",
"Comment": "",
"Created": "2019-10-01T23:19:57.105928163Z",
"Container": "711572e3c0c1ac06d5c13c4e668ec170b8ad8786b5f0949f884a5f7fd350d856",
"ContainerConfig": {
"Hostname": "711572e3c0c1",
"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 [\"/bin/bash\"]"
],
"ArgsEscaped": true,
"Image": "sha256:c0bda62fdbad65a3c6a1843d293a3a47d8233115cc6d384e3cb07c53580a2b43",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"DockerVersion": "18.06.1-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": [
"/bin/bash"
],
"ArgsEscaped": true,
"Image": "sha256:c0bda62fdbad65a3c6a1843d293a3a47d8233115cc6d384e3cb07c53580a2b43",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "",
"org.label-schema.license": "GPLv2",
"org.label-schema.name": "CentOS Base Image",
"org.label-schema.schema-version": "1.0",
"org.label-schema.vendor": "CentOS"
}
},
"Architecture": "amd64",
"Os": "linux",
"Size": ,
"VirtualSize": ,
"GraphDriver": {
"Data": {
"MergedDir": "/var/lib/docker/overlay2/166424768dce2d380cf1fe7cd570b2b72feb3b5768859101e5b5d46aa87ccc8d/merged",
"UpperDir": "/var/lib/docker/overlay2/166424768dce2d380cf1fe7cd570b2b72feb3b5768859101e5b5d46aa87ccc8d/diff",
"WorkDir": "/var/lib/docker/overlay2/166424768dce2d380cf1fe7cd570b2b72feb3b5768859101e5b5d46aa87ccc8d/work"
},
"Name": "overlay2"
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:9e607bb861a7d58bece26dd2c02874beedd6a097c1b6eca5255d5eb0d2236983"
]
},
"Metadata": {
"LastTagTime": "0001-01-01T00:00:00Z"
}
}
]
5 镜像的删除操作
[root@docker-server3 ~]# docker rmi 0f3e07c0138f
Untagged: centos:latest
Untagged: centos@sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Deleted: sha256:0f3e07c0138fbe05abcb7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da
Deleted: sha256:9e607bb861a7d58bece26dd2c02874beedd6a097c1b6eca5255d5eb0d2236983
当镜像有容器存在时
[root@docker-server3 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
acd538e93dec redis:4.0 "docker-entrypoint.s…" hours ago Up hours /tcp zen_raman
5e82ea0e65f0 centos: "/bin/bash" hours ago Up hours romantic_lewin
[root@docker-server3 ~]# docker rmi 5e35e350aded
Error response from daemon: conflict: unable to delete 5e35e350aded (cannot be forced) - image is being used by running container 5e82ea0e65f0
强制删除
[root@docker-server3 ~]# docker rmi -f 5e35e350aded
Error response from daemon: conflict: unable to delete 5e35e350aded (cannot be forced) - image is being used by running container 5e82ea0e65f0
运行的容器,镜像是无法删除的,停止容器
[root@docker-server3 ~]# docker stop 5e82ea0e65f0
再次删除镜像
[root@docker-server3 ~]# docker rmi -f 5e35e350aded
Untagged: centos:
Untagged: centos@sha256:4a701376d03f6b39b8c2a8f4a8e499441b0d567f9ab9d58e4991de4472fb813c
Deleted: sha256:5e35e350aded98340bc8fcb0ba392d809c807bc3eb5c618d4a0674d98d88bccd
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 e263c3a3ce1f days ago .2MB
httpd 2.4 c2aa7e16edd8 days ago 165MB
nginx latest 540a289bab6c months ago 126MB
hub.darren.com/library/nginx version1 540a289bab6c months ago 126MB
goodsmileduck/redis-cli latest 4b2315bf1ad2 months ago .9MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.1. b3b94275d97c months ago .6MB
centos7的镜像已经被删除
6 修改镜像名,打标签
[root@docker-server3 ~]# docker tag nginx:latest hub.darren.com/library/nginx:version1
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis 4.0 e263c3a3ce1f days ago .2MB
httpd 2.4 c2aa7e16edd8 days ago 165MB
hub.darren.com/library/nginx version1 540a289bab6c 2 months ago 126MB
nginx latest 540a289bab6c 2 months ago 126MB
centos latest 0f3e07c0138f months ago 220MB
goodsmileduck/redis-cli latest 4b2315bf1ad2 months ago .9MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns 1.1. b3b94275d97c months ago .6MB
7 镜像的导入和导出
删除掉所有的镜像
拉去两个镜像
[root@docker-server3 ~]# docker pull busybox
[root@docker-server3 ~]# docker pull alpine
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 6d5fcfe5ff17 days ago .22MB
alpine latest cc0abc535e36 days ago .59MB
[root@docker-server3 ~]# docker tag alpine:latest hub.darren.com/library/alpine:3.7
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 6d5fcfe5ff17 days ago .22MB
alpine latest cc0abc535e36 days ago .59MB
hub.darren.com/library/alpine 3.7 cc0abc535e36 days ago .59MB
镜像不是一个文件
[root@docker-server3 ~]# cd /var/lib/docker/image/overlay2/
[root@docker-server3 overlay2]# ll
drwx------ root root Nov : distribution
drwx------ root root Nov : imagedb
drwx------ root root Nov : layerdb
-rw------- root root Dec : repositories.json
导出
[root@docker-server3 ~]# docker save -o alpine:3.7.tar hub.darren.com/library/alpine:3.7
[root@docker-server3 ~]# ll
-rw------- root root Dec : alpine:3.7.tar
[root@docker-server3 ~]# docker rmi -f cc0abc535e36
Untagged: alpine:latest
Untagged: alpine@sha256:2171658620155679240babee0a7714f6509fae66898db422ad803b951257db78
Untagged: hub.darren.com/library/alpine:3.7
Deleted: sha256:cc0abc535e36a7ede71978ba2bbd8159b8a5420b91f2fbc520cdf5f673640a34
Deleted: sha256:6b27de954cca6332272e7709b7d8ceccee1489d9452af73391df360a26123580
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 6d5fcfe5ff17 days ago .22MB
导入
[root@docker-server3 ~]# docker load --input alpine\:3.7.tar
6b27de954cca: Loading layer [==================================================>] .857MB/.857MB
Loaded image: hub.darren.com/library/alpine:3.7
[root@docker-server3 ~]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest 6d5fcfe5ff17 days ago .22MB
hub.darren.com/library/alpine 3.7 cc0abc535e36 days ago .59MB
容器的镜像管理结束
博主声明:本文的内容来源主要来自誉天教育晏威老师,由本人实验完成操作验证,需要的博友请联系誉天教育(http://www.yutianedu.com/),获得官方同意或者晏老师(https://www.cnblogs.com/breezey/)本人同意即可转载,谢谢
DOCKER学习_009:Docker的镜像管理的更多相关文章
- Docker学习(二): 镜像的使用与构建
特别声明: 博文主要是学习过程中的知识整理,以便之后的查阅回顾.部分内容来源于网络(如有摘录未标注请指出).内容如有差错,也欢迎指正! =============系列文章============= 1 ...
- Docker学习之Docker镜像基本使用
Docker学习之Docker镜像基本使用 获取镜像 命令格式:docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签] 例如: docker pull ...
- Docker学习笔记 — Docker私有仓库搭建
Docker学习笔记 — Docker私有仓库搭建 目录(?)[-] 环境准备 搭建私有仓库 测试 管理仓库中的镜像 查询 删除 Registry V2 和Mavan的管理一样,Dockers ...
- Docker学习之Docker容器基本使用
Docker学习之Docker容器基本使用 新建容器并启动 命令格式:docker run --options repository:tag 后台运行 命令格式:-d 已存在的容器相关操作 启动:do ...
- DOCKER学习_016:Docker镜像仓库和HARBOR的简单安装和管理
一 镜像仓库介绍 1.1 简介 镜像仓库用于存放 Docker镜像 Docker registry提供镜像仓库服务 一个 Docker registry可以包含多个镜像仓库 仓库分为公共镜像仓库与私有 ...
- Docker 学习3 Docker镜像管理基础
一.docker 常用操作及原理 1.docker 常用操作 2.docker 机制 1.docker client端是通过http或者https与server端通信的.个 2.docker 镜像可以 ...
- docker学习笔记3:镜像操作(查找和下载)
一.查看本地镜像 只有下载后,镜像才会保存在本地(docker环境所在的主机),通过如下命令可以查看本地已经存在的镜像. 命令:dokcer images 上面命令列出本地所有已经存在的镜像,显示的信 ...
- Docker学习笔记之运行和管理容器
0x00 概述 容器是基于容器技术所建立和运行的轻量级应用运行环境,它是 Docker 封装和管理应用程序或微服务的“集装箱”.在 Docker 中,容器算是最核心的部分了,掌握容器的操作也是 Doc ...
- Docker学习笔记之从镜像仓库获得镜像
0x00 概述 之前我们说到了,Docker 与其他虚拟化软件的一处不同就是将镜像管理纳入到了功能之中.实现虚拟化只是程序能够无缝移植的一部分,而有了镜像管理,就真正取代了我们在移植过程中的繁琐操作. ...
随机推荐
- CPU核数和线程数查找
方法1: 方法2:
- PHP判断图片格式的七种方法小结
<?php $imgurl = "http://www.jb51.net/images/logo.gif"; //方法1 echo $ext = strrchr($imgur ...
- 随机数专题 Day08
package com.sxt.arraytest2; import java.util.Arrays; /* * 随机数专题 * Math类的random()方法 * m~n的随机数 * 公式:(i ...
- js+canvas黑白棋
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- CentOs7.0安装scrapy (云服务器上)
centos7 默认Python 2.7,支持twisted 首先准备环境 yum install gcc libffi-devel openssl-devel libxml2 libxslt-dev ...
- Python学习(四)cPickle的用法
python中有两个类似的:pickle与cPickle:两者的关系:“cPickle – A faster pickle” pickle模块中的两个主要函数是dump()和load().dump() ...
- util.date
package com.sxt.utils.date1; import java.util.Date; /* * util.date */ public class TestDate { public ...
- OracleSpatial函数实例
Oracle Spatial操作geometry方法 Oracle Spatial中SDO_GEOMETRY类型: CREATE TYPE SDO_GEOMETRY AS OBJECT( SDO_ ...
- <肖申克的救赎>观后感
肖申克的救赎主要讲述了银行家安迪在不健全的法律制度下被陷害进入了--鲨堡监狱,最后为了重见光明.追求自由,实现“自我救赎”的故事. 1.希望是件好东西,也许是世上最好的东西.好东西从来不会流逝. Ho ...
- CSS长度单位:px和pt的区别
先搞清基本概念:px就是表示pixel,像素,是屏幕上显示数据的最基本的点:而pt就是point,是印刷行业常用单位,等于1/72英寸. 这样很明白,px是一个点,它不是自然界的长度单位,谁能说出一个 ...