赞
踩
目录
构建镜像的时候,包含不需要的文件会导致更大的构建上下文合更大的镜像大小,会增加构建镜像、拉取镜像、推送镜像的时间 以及 容器运行时的时间
- FROM busybox
- COPY /hello /
- RUN cat /hello
hello world !!!

最后的 . 代表的是要打包镜像的上下文, 该文件内的所有内容都会打包到镜像里面
docker build -t helloapp:v1 .
镜像打包的结果为 3.072KB


mkdir -p dockerfiles context
mv Dockerfile dockerfiles
mv hello context
docker build --no-cache -t helloapp:v2 -f dockerfiles/Dockerfile context

echo 'world' > context/world.txt
touch context/.dockerignore

docker build --no-cache -t helloapp:v3 -f dockerfiles/Dockerfile context

可以看到 .dockerignore 文件内,忽略的文件没有被打到镜像中
docker images | grep hello

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。