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 -
e.g. consider this image - mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
When I use the --pull
flag,
docker build --pull
?
- Would it pull aspnetcore 3.1 version if available?
No, because it wouldn't be tagged :3.0-buster-slim
.
- Would it pull nightly build if available?
No, because it wouldn't be tagged :3.0-buster-slim
.
- 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
- 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