6.1 什么是image
- 文件和meta data的集合(root filesystem)
- 分层的,并且每一层都可以添加、改变、删除文件,成为一个新的image
- 不同的image可以共享相同的layer
- image本身是read-only的
6.2 image的获取
- Build from Dockerfile
- Pull from Registry
- commit from a container's changes
通过Dockerfile构建一个base image
- 编写一个c文件并编译成为可执行文件
#include<stdio.h>
int main()
{
printf("hello docker
");
}
gcc -static hello.c -o hello
- 编写Dockerfile文件
FROM scratch
ADD hello /
CMD ["/hello"]
- 通过docker build构建镜像
命令:
docker image build <==> docker build
docker build -t staryjie/hello-docker .
Sending build context to Docker daemon 868.9kB
Step 1/3 : FROM scratch
--->
Step 2/3 : ADD hello /
---> d6f5edefd7fa
Step 3/3 : CMD ["/hello"]
---> Running in e1db264875b9
Removing intermediate container e1db264875b9
---> 09be7d865fab
Successfully built 09be7d865fab
Successfully tagged staryjie/hello-docker:latest
- 通过docker history查看镜像的分层
命令:
docker history
docker history staryjie/hello-docker:latest
IMAGE CREATED CREATED BY SIZE COMMENT
09be7d865fab 4 minutes ago /bin/sh -c #(nop) CMD ["/hello"] 0B
d6f5edefd7fa 4 minutes ago /bin/sh -c #(nop) ADD file:e98243ff005d26728… 865kB