docker/docker-compose 构建 --pull 行为
docker/docker-compose build --pull behavior
我正在尝试了解 docker build --pull
/docker-compose build --pull
选项的工作原理。
我找到了 link - https://docs.docker.com/compose/reference/build/
它只说 -
Always attempt to pull a newer version of the image.
但我还有一些问题没有得到解答 -
例如考虑这张图片 - mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
当我使用 --pull
标志时,
- 如果有的话会拉aspnetcore 3.1版本吗?
- 如果可用,它会拉取每晚构建吗?
- 会不会不管本地镜像和最新镜像是否相同,都会下载?
- 如果机器在 运行
docker build --pull
期间没有互联网连接会怎样?
- 没有
- 没有
- 它将始终使用 name:tag
mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
检查新图像
- 它应该因错误而失败
- Would it pull aspnetcore 3.1 version if available?
不,因为它不会被标记 :3.0-buster-slim
。
- Would it pull nightly build if available?
不,因为它不会被标记 :3.0-buster-slim
。
- Would it always download the image regardless if the local image and the latest image are same?
没有。如果本地和远程 sha256 哈希值不同,它将下载更新。如果它们相同,则不会重新下载。没有意义。
让我们用一个简单的一行 Dockerfile 来测试它:
FROM alpine:latest
第一次:
$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest
后续构建:
$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Image is up to date for alpine:latest
- What would happen if the machine doesn't have internet connectivity while running
docker build --pull
?
构建失败。禁用网络后,--pull
失败:
$ docker build --pull .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM alpine:latest
Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 127.0.0.53:53: server misbehaving
没有 --pull
它有效:
$ docker build .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM ubuntu:latest
---> a2a15febcdf3
Successfully built a2a15febcdf3
我正在尝试了解 docker build --pull
/docker-compose build --pull
选项的工作原理。
我找到了 link - https://docs.docker.com/compose/reference/build/
它只说 -
Always attempt to pull a newer version of the image.
但我还有一些问题没有得到解答 -
例如考虑这张图片 - mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
当我使用 --pull
标志时,
- 如果有的话会拉aspnetcore 3.1版本吗?
- 如果可用,它会拉取每晚构建吗?
- 会不会不管本地镜像和最新镜像是否相同,都会下载?
- 如果机器在 运行
docker build --pull
期间没有互联网连接会怎样?
- 没有
- 没有
- 它将始终使用 name:tag
mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
检查新图像
- 它应该因错误而失败
- Would it pull aspnetcore 3.1 version if available?
不,因为它不会被标记 :3.0-buster-slim
。
- Would it pull nightly build if available?
不,因为它不会被标记 :3.0-buster-slim
。
- Would it always download the image regardless if the local image and the latest image are same?
没有。如果本地和远程 sha256 哈希值不同,它将下载更新。如果它们相同,则不会重新下载。没有意义。
让我们用一个简单的一行 Dockerfile 来测试它:
FROM alpine:latest
第一次:
$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest
后续构建:
$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Image is up to date for alpine:latest
- What would happen if the machine doesn't have internet connectivity while running
docker build --pull
?
构建失败。禁用网络后,--pull
失败:
$ docker build --pull .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM alpine:latest
Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 127.0.0.53:53: server misbehaving
没有 --pull
它有效:
$ docker build .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM ubuntu:latest
---> a2a15febcdf3
Successfully built a2a15febcdf3