[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
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.
Parent Image
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.