Open scaytrase opened 6 years ago
Hm, I'm not sure I agree with proceeding in that case; by passing the --pull
flag, you're explicitly asking. docker to pull the image; failing the build of the pull fails seems the right action here (instead of silently ignoring that the pull failed)
@tonistiigi @cpuguy83 WDYT?
@thaJeztah Yes, possible security problem if we would fallback. There could be a special syntax for specifying the desired behavior here though. Not sure what that would look like.
Currently we have to overcome it with
(docker pull parent || docker build parent) && docker build child
to make sure that parent image is fresh or pulled from outer repo, since the docker --pull build parent
just fails if pull fail.
Current behavior of docker --pull
build renders like
(docker pull parent && docker build parent)
part instead, which gives us less flexibility
I'm having trouble understanding the use-case; by passing --pull
to docker build
you indicate that the registry should be the source of truth (i.e., use the latest version of the image as available in the registry), but your description doesn't match that expectation.
--pull
No mybaseimage
present in the registry, and no mybaseimage
present locally:
FROM mybaseimage:latest
mybaseimage
is not found)No mybaseimage
present in the registry, and no mybaseimage
present locally:
mybaseimage
FROM mybaseimage:latest
mybaseimage
that was just built)No mybaseimage
present in the registry, and no mybaseimage
present locally:
mybaseimage
mybaseimage
FROM mybaseimage:latest
mybaseimage
)No mybaseimage
present in the registry, and no mybaseimage
present locally:
mybaseimage
mybaseimage
mybaseimage
(local image is now more current than mybaseimage
in the registry)FROM mybaseimage:latest
mybaseimage
)mybaseimage
present in the registry, but no mybaseimage
present locally:
FROM mybaseimage:latest
mybaseimage:latest
from the registry (because no image was present locally)mybaseimage
that was just pulled)--pull
No mybaseimage
present in the registry, and no mybaseimage
present locally:
FROM mybaseimage:latest
mybaseimage
is not found in registry)No mybaseimage
present in the registry, and no mybaseimage
present locally:
mybaseimage
FROM mybaseimage:latest
mybaseimage
is not found in registry)No mybaseimage
present in the registry, and no mybaseimage
present locally:
mybaseimage
mybaseimage
FROM mybaseimage:latest
mybaseimage:latest
, replacing the local mybaseimage:latest
mybaseimage
that was just pulled)No mybaseimage
present in the registry, and no mybaseimage
present locally:
mybaseimage
mybaseimage
mybaseimage
(local image is now more current than mybaseimage
in the registry)FROM mybaseimage:latest
mybaseimage:latest
, replacing the local mybaseimage:latest
mybaseimage
that was just pulled)mybaseimage
present in the registry, but no mybaseimage
present locally:
FROM mybaseimage:latest
mybaseimage:latest
from the registrymybaseimage
that was just pulled)Perhaps you can describe your use-case a bit more; what's the reason for adding --pull
?
docker build
without --pull
)I think it's not good idea to manipulate the flag value base on knownledge, whether FROM already pushed to remote repo or not
Using --pull
without this knowledge can be problematic: Situation 4B describes why it can be problematic; when using --pull
in that situation, you will always overwrite your local image, potentially loosing the latest version of the image that you just built.
Based on the above, I agree with @tonistiigi that we should not change the behavior of --pull
in its current form.
Having said that, I can see possible improvements, for example:
--pull=always
current behavior: always attempt to pull the image, and fail if the image could not be pulled--pull=changed
pull if the image's digest on the registry is different than the local image (does not have to be "newer")--pull=newer
pull if the image in the registry was built (or pushed?) more recently than the image that's available locally (to prevent overwriting a local image)
.Created
date/time@thaJeztah yes, the use-case is to update baseimage
from remote registry if updated version available. This is needed for the CI cince images are stored on per-agent basis, so without pulling attempt we get the folloiwing:
build nr. 1, agent 1: build image_v1 - no base found, build baseimage_v1, push both build nr. 2, agent 2: build image_v2 - no base found, build baseimage_v2, push both build nr. 3, agent 1: build image_v3 - baseimage_v1 found - use stale image, push image_v3 based on it
your enhancement ideas looks good for me, I see both --pull=newer
and --pull=changed
solving our problem
so without pulling attempt we get the folloiwing:
With the "fallback" (as you originally proposed), that problem wouldn't be solved, as in that case, the flow would look like:
build nr. 3, agent 1: build image_v3 -> pull baseimage
-> failed -> local baseimage_v1
found -> use stale image, push image_v3 based on it
So, yes, newer
or changed
could address that, but would still raise the question if build should succeed when failing to pull (i.e. image does not exist in the registry at all). Falling back to a local image when requesting an image from the registry can be a security concern (i.e., it's easy to "spoof" the local image cache, and (say) docker build -t ubuntu:16.04 FROM myubuntu:bitcoin-miner
I think the whole local cache itself exposes a security vulnerability, so using --pull=always
by default should make thing as safe as before, allowing to explicitly use cache with --pull=newer
. Btw --pull=changed
should also be safe as soon as local image is always changed against remote if spoofed
Looks like the
--pull
option disallows fallback to locally installed image if pull attempt failed. If I remove--pull
flag from buildingB
image - everything works OK. I think it's not good idea to manipulate the flag value base on knownledge, whetherFROM
already pushed to remote repo or notDescription
A/Dockerfile
B/Dockerfile
make-a: docker build --pull -t local_a:latest A/
make-b: make-a docker build --pull -t local_b:latest B/
PS C:\Work\Projects\tmp\dockerfile-pull-repro> make docker build --pull -t local_a:latest A/ Sending build context to Docker daemon 2.048kB Step 1/1 : FROM alpine:latest latest: Pulling from library/alpine Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0 Status: Image is up to date for alpine:latest ---> 3fd9065eaf02 Successfully built 3fd9065eaf02 Successfully tagged local_a:latest docker build --pull -t local_b:latest B/ Sending build context to Docker daemon 2.048kB Step 1/1 : FROM local_a pull access denied for local_a, repository does not exist or may require 'docker login' make: *** [Makefile:7: make-b] Error 1
PS C:\Work\Projects\tmp\dockerfile-pull-repro> make docker build --pull -t php:8-fpm A/ Sending build context to Docker daemon 2.048kB Step 1/1 : FROM alpine:latest latest: Pulling from library/alpine Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0 Status: Image is up to date for alpine:latest ---> 3fd9065eaf02 Successfully built 3fd9065eaf02 Successfully tagged php:8-fpm docker build --pull -t local_b:latest B/ Sending build context to Docker daemon 2.048kB Step 1/1 : FROM php:8-fpm manifest for php:8-fpm not found make: *** [Makefile:7: make-b] Error 1
Client: Version: 17.07.0-ce API version: 1.31 Go version: go1.8.3 Git commit: 8784753 Built: Tue Aug 29 17:41:05 2017 OS/Arch: windows/amd64
Server: Version: 17.12.0-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.2 Git commit: c97c6d6 Built: Wed Dec 27 20:09:19 2017 OS/Arch: linux/amd64 Experimental: false
Containers: 9 Running: 5 Paused: 0 Stopped: 4 Images: 670 Server Version: 17.12.0-ce Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 394 Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 89623f28b87a6004d4b785663257362d1658a729 runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f init version: 949e6fa Security Options: apparmor seccomp Profile: default Kernel Version: 4.13.0-38-generic Operating System: Ubuntu 17.10 OSType: linux Architecture: x86_64 CPUs: 4 Total Memory: 1.946GiB Name: payment-method ID: RH7N:DMCY:GJO6:XLOG:2N55:BUEU:MDN2:7M5T:GJUC:OIY6:2SXR:GX6O Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false
WARNING: No swap limit support