问题
Is there a way to build and tag all stages of a multistage build? A verbose (and somewhat slow) workaround is to call docker build
several times:
DOCKER_BUILDKIT=1 docker build
--target builder
--tag bdr
DOCKER_BUILDKIT=1 docker build
--target build
--tag bd
DOCKER_BUILDKIT=1 docker build
--target runtime
--tag rt
DOCKER_BUILDKIT=1 docker build
--target test
--tag tst
EDIT: In my case every call to docker build
includes ~2 seconds of overhead:
#1 [internal] load .dockerignore
#1 transferring context: 34B done
#1 DONE 0.6s
#2 [internal] load build definition from Dockerfile
#2 DONE 0.7s
#3 [internal] load metadata for my_parent_image...
#3 DONE 0.7s
#4 [builder 1/6] FROM my_parent_image@s...
#4 DONE 0.0s
回答1:
This is a feature of docker buildx bake which is at last check still considered experimental and I haven't seen a lot of traction for the syntax from the community.
There's certainly been some discussion on adding this functionality in the buildkit issues and I'd recommend following those issues and adding your use case if you'd like to see it added.
来源:https://stackoverflow.com/questions/64807869/tag-all-stages-of-docker-multi-stage-build