6、Docker Image
阿新 • • 發佈:2019-01-17
containe roo run gist root ces size running 分享
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\n"); }
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
6、Docker Image