Docker image Introduce

简介:
Docker 的image是运行的基本.
例如我们build一个image时, 在Dockerfile每条指令会产生一个可读写的image, 下一条指令使用上一条指令产生的image为基础, 继续产生image(然后删除上一个image), 如果指令没有对image有修改的动作, 那么可以使用image cache. 所有的指令执行完, 生成最终的image.
然后我们就可以使用image来创建并运行container了.

例如我当前本地有一个images, centos, TAG是centos5, 我需要使用它作为base image, 来创建我自己的image.
[root@150 docker]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos                    centos5             d5844d902074        2 days ago          467.1 MB


创建一个空目录, 并在这个空目录中写一个简单的Dockerfile内容如下 : 
# vi Dockerfile 
FROM centos:centos5
CMD ["-l"]
ENTRYPOINT ["ls"]


使用docker build .来创建image.
[root@150 docker]# docker build .
Sending build context to Docker daemon  2.56 kB
Sending build context to Docker daemon 
Step 0 : FROM centos:centos5
 ---> d5844d902074   # 这个ID是centos:centos5的IMAGE id
Step 1 : CMD ["-l"]
 ---> Running in 9fd2f16fcf97   # 这个ID是执行第一条指令CMD ["-l]时产生的中间过程IMAGE ID
 ---> e253cb9b0ea4   # 这个ID是执行第一条指令CMD ["-l]后产生的IMAGE ID
Removing intermediate container 9fd2f16fcf97   #  移除中间image
Step 2 : ENTRYPOINT ["ls"]
 ---> Running in 52c06c9fae1b  
 ---> a18fae31b310
Removing intermediate container 52c06c9fae1b
Successfully built a18fae31b310    # 最终的ID, 可以使用docker images看到这个ID


[root@150 docker]# docker images
REPOSITORY                TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>                    <none>              a18fae31b310        14 minutes ago      467.1 MB
centos                    centos5             d5844d902074        2 days ago          467.1 MB


使用这个image运行
[root@150 docker]# docker run a18fae31b310
total 64
drwxr-xr-x   2 root root 4096 Sep 26 12:21 bin
drwxr-xr-x   4 root root  340 Sep 30 10:29 dev
drwxr-xr-x  39 root root 4096 Sep 30 10:29 etc
drwxr-xr-x   2 root root 4096 May 11  2011 home
drwxr-xr-x   6 root root 4096 Sep 26 12:20 lib
drwxr-xr-x   7 root root 4096 Sep 26 12:20 lib64
drwx------   2 root root 4096 Sep 26 12:19 lost+found
drwxr-xr-x   2 root root 4096 May 11  2011 media
drwxr-xr-x   2 root root 4096 May 11  2011 mnt
drwxr-xr-x   2 root root 4096 May 11  2011 opt
dr-xr-xr-x 372 root root    0 Sep 30 10:29 proc
drwxr-x---   2 root root 4096 May 11  2011 root
drwxr-xr-x   2 root root 4096 Sep 26 12:21 sbin
drwxr-xr-x   3 root root 4096 Sep 26 12:21 selinux
drwxr-xr-x   2 root root 4096 May 11  2011 srv
drwxr-xr-x  13 root root    0 Sep 30  2014 sys
drwxrwxrwt   2 root root 4096 Sep 26 12:21 tmp
drwxr-xr-x  14 root root 4096 Sep 26 12:20 usr
drwxr-xr-x  17 root root 4096 Sep 26 12:19 var

[root@150 docker]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
ae77e79c4f58        a18fae31b310        ls -l               29 seconds ago      Exited (0) 28 seconds ago                          desperate_lovelace 

[root@150 docker]# docker rm ae77e79c4f58
ae77e79c4f58
[root@150 docker]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES


image的介绍 : 

Introduction

Docker image Introduce - 德哥@Digoal - PostgreSQL research

 

In Docker terminology, a read-only Layer is called an image. An image never changes.

Since Docker uses a Union File System, the processes think the whole file system is mounted read-write. But all the changes go to the top-most writeable layer, and underneath, the original file in the read-only image is unchanged. Since images don't change, images do not have state.

Docker image Introduce - 德哥@Digoal - PostgreSQL research

 

Parent Image

Docker image Introduce - 德哥@Digoal - PostgreSQL research

Each image may depend on one more image which forms the layer beneath it. We sometimes say that the lower image is the parent of the upper image.

Base Image

An image that has no parent is a base image.

Image IDs

All images are identified by a 64 hexadecimal digit string (internally a 256bit value). To simplify their use, a short ID of the first 12 characters can be used on the command line. There is a small possibility of short id collisions, so the docker server will always return the long ID.


[参考]
目录
相关文章
|
Linux Docker 容器
「Docker」M1 Pro 打包docker image问题合集
「Docker」M1 Pro 打包docker image问题合集
308 0
|
Linux Docker Windows
docker pull 报错解决:error pulling image configuration: Get https:..
docker pull 报错解决:error pulling image configuration: Get https:..
4433 0
|
8月前
|
存储 运维 应用服务中间件
Docker Image即Docker镜像
Docker 镜像是 Docker 容器的基础,包含了运行应用程序所需的一切。通过 Dockerfile 可以方便地创建自定义镜像,并且利用 Docker 提供的命令可以轻松管理和使用这些镜像。掌握 Docker 镜像的创建、管理和使用,是进行容器化应用开发和部署的基础技能。希望本文能帮助读者更好地理解 Docker 镜像的概念和操作,提高开发和运维效率。
1097 13
|
12月前
|
网络虚拟化 Docker 容器
docker Desktop报错 error pulling image configuration 处理
docker Desktop报错 error pulling image configuration 处理
196 0
|
JSON Ubuntu 持续交付
用skopeo检查docker image
通过Skopeo,您可以方便地获取Docker镜像的详细信息和元数据,而不需要拉取或安装整个镜像。这对于那些有成百上千镜像的大型系统是非常实用的,因为它有助于快速查看和分析镜像的特定属性。Skopeo是一个专业的工具,用于在持续集成和部署的过程中实现高效的镜像管理,既减轻了对Docker守护进程的依赖,也为容器化环境中镜像的控制提供了灵活性。
211 3
|
安全 API Docker
docker image的发布
docker image的发布
151 0
|
Ubuntu Unix Linux
Docker 镜像(image)& 容器(container)
什么是 Docker 镜像(image)? 镜像由多个层组成,每层叠加之后,从外部看来就如一个独立的对象; 镜像内部是一个精简的操作系统(OS),同时还包含应用运行所必须的文件和依赖包; 镜像可以运行一个或多个容器,同时镜像也可以停止某个容器的运行,并从中创建新的镜像;【镜像(iamge)的分类】...
1036 1
Docker 镜像(image)& 容器(container)
|
Kubernetes 安全 Linux
From Docker to Kubernetes(一)- Image And Container
From Docker to Kubernetes(一)- Image And Container
From Docker to Kubernetes(一)- Image And Container
|
Java Linux Docker
Docker image设计与Linux哲学的关系
最近在阅读Linux 系统编程手册。
130 0