Docker image Introduce
例如我當前本地有一個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
?
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.
[參考] 1.?http://docs.docker.com/terms/image/
總結
以上是生活随笔為你收集整理的Docker image Introduce的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server2008数据库置疑修
- 下一篇: 测试人员代码走查基础要点