简体   繁体   中英

docker/docker-compose build --pull behavior

I am trying to find how docker build --pull / docker-compose build --pull option works. I found a link - https://docs.docker.com/compose/reference/build/ All it says is that -

Always attempt to pull a newer version of the image.

But I still have some questions unanswered -

eg consider this image - mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim

When I use the --pull flag,

  1. Would it pull aspnetcore 3.1 version if available?
  2. Would it pull nightly build if available?
  3. Would it always download the image regardless if the local image and the latest image are same?
  4. What would happen if the machine doesn't have internet connectivity while running docker build --pull ?
  1. Would it pull aspnetcore 3.1 version if available?

No, because it wouldn't be tagged :3.0-buster-slim .

  1. Would it pull nightly build if available?

No, because it wouldn't be tagged :3.0-buster-slim .

  1. Would it always download the image regardless if the local image and the latest image are same?

No. It will download an update if the local and remote sha256 hashes differ. If they're the same it won't re-download it. There's no point.

Let's test it with a simple one-line Dockerfile:

FROM alpine:latest

First time:

$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest

Subsequent builds:

$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Image is up to date for alpine:latest
  1. What would happen if the machine doesn't have internet connectivity while running docker build --pull ?

The build fails. With networking disabled, --pull fails:

$ 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                           

Without --pull it works:

$ docker build .
Sending build context to Docker daemon  2.048kB
Step 1/1 : FROM ubuntu:latest
 ---> a2a15febcdf3
Successfully built a2a15febcdf3
  1. no
  2. no
  3. it will always check for a new image with the name:tag mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
  4. it should fail with error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM