You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pull request docker/cli#1498 added a --pull option to docker run and docker create (to address moby/moby#34394), which allows the pull-policy to be configured to use, and has three options:
--pull
description
(not set)
(default) pull the image if it does not exist locally
--pull=missing
same as default above
--pull=never
don't pull the image, but produce an error if the image does not exist
--pull=always
always attempt to pull the image, even if the image exists locally: produce an error if pull failed
docker build also has a --pull flag, but is implemented as a boolean:
--pull
description
(not set)
(default) pull the image if it does not exist locally
--pull=false
same as above
--pull / --pull=true
always attempt to pull the image, even if the image exists locally: produce an error if pull failed. This is the equivalent of --pull=always on docker run
Proposal
I think it would make sense to have docker build support the same options as docker run. For backward-compatibility, --pull would be the equivalent of --pull=always:
--pull
description
(not set)
(default) pull the image if it does not exist locally
--pull=missing
same as default above
--pull=never
don't pull the image, but produce an error if the image does not exist
--pull=always
always attempt to pull the image, even if the image exists locally: produce an error if pull failed
--pull
equivalent to --pull=always. kept for backward compatibility
Reacted by Felipe Santos, Gilad Peleg, Sébastien Mascha, Tim Brown, KUGA2, Alex Zolotko, Jaka Jančar, yozu-dwatts, Ken Clarke, Craig P Hicks and 4 more
--pull=missing, unset --pull are equivalent to --pull=false.
actually, the last one is one I didn't look at. Likely a "corner case", but wondering if it would be less surprising if --pull=false would be equivalent to --pull=never. I haven't checked how docker/cli#1498 handles that (and if changing would be a breaking change 🤔)
We can have this implemented by few modifications at client side itself.
We may have to look at docker build with buildkit enabled (DOCKER_BUILDKIT=1), also with multi-stage builds in mind (so there's not a single image to check, and names of images used in specific stages could depend on ARG values). I haven't looked into that yet
#1889 looks perfect. --pull=never would be a very handy feature for using locally built images as base for another. Especially when using docker buildx bake.
Fwiw, this would be a breaking change unless you really carefully implement it as described above.
We've just been bitten by the argument parsing of --pull on the run command, that doesn't validate the values, so our docker run --pull --rm … actually was parsed as --pull=--rm, without any runtime error. This has two side effects:
the current implementation of the run command only compares the value with always and missing, so any other value is effectivement equivalent to never
I'm not sure if the CLI library allows updating this in backward compatible way but assuming it does:
--pull=never | don't pull the image, but produce an error if the image does not exist
This would require BuildKit change. There is no current ResolveMode implementation with these semantics.
What's missing from the list is the "fallback mode" (not sure what would be the correct name) that is the default in buildkitd without docker imagestore. In this mode, you always get the latest version of the image, but you can still use local images as well. If the build fails because there is no remote image with that name or you don't have an active network connection, then it will fall back to using a local version of the image.
I'm not sure if the CLI library allows updating this in backward compatible way
Honest answer: "close", but not fully.
We did this for docker run, and thought we covered all scenarios (--pull without value is always, --pull=true, --pull=false)
But there's one exception that we overlooked; docker run --pull -it ubuntu works, but docker run -it --pull ubuntu will produce an error, because ubuntu will be set as value for --pull.
In either case, I think this ticket would now better be in the buildx repository (although we may have to implement it for the classic builder as well for parity once it's implemented there). Let me migrate it to there 👍
Any news on this? From the user's perspective, BuildKit broke offline, the OG backend is now deprecated, and as of Docker 29.4, there is still no --pull=missing:
There is thankfully the workaround of pinning the base images by sha256sum instead of by tag, but tags were satisfactory and used to work, while sha256sums is a bit of maintenance burden that feels unnecessary: Surely, it must be possible to figure out that a base image with the right tag exists locally without reaching out to the internet each time.
Reacted by AbsurdlySuspicious, vegas503 and Benedikt Radtke
There is thankfully the workaround of pinning the base images by sha256sum instead of by tag, but tags were satisfactory and used to work, while sha256sums is a bit of maintenance burden that feels unnecessary: Surely, it must be possible to figure out that a base image with the right tag exists locally without reaching out to the internet each time.
💯I often have to build hotfix images in the middle of nowhere, and depending on a working uplink is unbearable.
Activity
thaJeztah commentedon Jan 15, 2020
@tonistiigi wdyt?
Madhur1997 commentedon Jun 25, 2020
Hey @thaJeztah,
I was going through the code flow for this.
We can have this implemented by few modifications at client side itself.
if imageExistsLocally {
build(--pull=missing)
} else {
log(err)
}
How does this sound to you?
Please let me know if you have any suggestions.
I would like to take this up.
thaJeztah commentedon Jun 25, 2020
actually, the last one is one I didn't look at. Likely a "corner case", but wondering if it would be less surprising if
--pull=falsewould be equivalent to--pull=never. I haven't checked how docker/cli#1498 handles that (and if changing would be a breaking change 🤔)We may have to look at
docker buildwith buildkit enabled (DOCKER_BUILDKIT=1), also with multi-stage builds in mind (so there's not a single image to check, and names of images used in specific stages could depend onARGvalues). I haven't looked into that yet@tonistiigi @AkihiroSuda any thoughts?
felipecrs commentedon Sep 24, 2021
#1889 looks perfect.
--pull=neverwould be a very handy feature for using locally built images as base for another. Especially when usingdocker buildx bake.tbroyer commentedon Jun 21, 2022
Fwiw, this would be a breaking change unless you really carefully implement it as described above.
We've just been bitten by the argument parsing of
--pullon theruncommand, that doesn't validate the values, so ourdocker run --pull --rm …actually was parsed as--pull=--rm, without any runtime error. This has two side effects:runcommand only compares the value withalwaysandmissing, so any other value is effectivement equivalent tonever--rmwas eaten silently(I opened docker/cli#3681 about this)
tonistiigi commentedon Jun 15, 2023
I'm not sure if the CLI library allows updating this in backward compatible way but assuming it does:
This would require BuildKit change. There is no current ResolveMode implementation with these semantics.
What's missing from the list is the "fallback mode" (not sure what would be the correct name) that is the default in buildkitd without docker imagestore. In this mode, you always get the latest version of the image, but you can still use local images as well. If the build fails because there is no remote image with that name or you don't have an active network connection, then it will fall back to using a local version of the image.
felipecrs commentedon Jun 15, 2023
No matter what I believe it would be nice to have a similar syntax between
runandbuild, while still retaining backwards compatibility, i.e:--pulland--pull=truetranslates to--pull=always,--pull=falsetranslates to--pull=missing.thaJeztah commentedon Jun 15, 2023
Honest answer: "close", but not fully.
We did this for
docker run, and thought we covered all scenarios (--pullwithout value isalways,--pull=true,--pull=false)But there's one exception that we overlooked;
docker run --pull -it ubuntuworks, butdocker run -it --pull ubuntuwill produce an error, becauseubuntuwill be set as value for--pull.thaJeztah commentedon Jun 15, 2023
In either case, I think this ticket would now better be in the
buildxrepository (although we may have to implement it for the classic builder as well for parity once it's implemented there). Let me migrate it to there 👍[-][proposal] implement docker build --pull=missing|never|always[/-][+][proposal] implement pull-policies (docker build --pull=missing|never|always)[/+]Cache package build base images more aggressively (#26756)
anordal commentedon Jun 1, 2026
Any news on this? From the user's perspective, BuildKit broke offline, the OG backend is now deprecated, and as of Docker 29.4, there is still no --pull=missing:
There is thankfully the workaround of pinning the base images by sha256sum instead of by tag, but tags were satisfactory and used to work, while sha256sums is a bit of maintenance burden that feels unnecessary: Surely, it must be possible to figure out that a base image with the right tag exists locally without reaching out to the internet each time.
beanscg commentedon Jun 10, 2026
Trolldemorted commentedon Nov 20, 2026
💯I often have to build hotfix images in the middle of nowhere, and depending on a working uplink is unbearable.
Would a PR that adresses this be accepted?