-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug?] docker-compose.yml using build unable to access image from previous service-build #2024
Comments
Just for notice. As my build and work got stuck on this issue I've merged all service Dockerfiles into one using different targets to specify which image should be used for service-a and service-b. This build seems to work now by referencing the internal stage (AS xyz) instead of the same stage being build as base-image. But this isn't what I would expect to get this working in a more clean manner. This is simply a workaround. Neither referencing using an external registry, nor using additional_contexts worked for me as they should do. |
Thanks for your report and sorry for the delay!
A container builder (
The way you're using the named context is racy and will not work. When using a named context you want to use the build result of the target. In your case you want to use build result of services:
service-a:
image: ${REGISTRY:-registry.local.docker}/service-a:local
build:
context: docker/
dockerfile: Dockerfile.service-a
target: release
service-b:
image: ${REGISTRY:-registry.local.docker}/service-b:local
depends_on:
- service-a
build:
context: docker/
dockerfile: Dockerfile.service-b
target: release
additional_contexts:
base-image: "target:service-a" But it doesn't seem to work either:
Looks like compose try to solve the absolute path of the named context which is wrong (cc @glours @milas). If you're using compose to just build, I would suggest to switch to bake and an HCL definition. Tried your repro with Bake and works for me: # docker-bake.hcl
group "default" {
targets = ["service-b"]
}
target "service-a" {
context = "./docker"
dockerfile = "Dockerfile.service-a"
target = "release"
}
target "service-b" {
context = "./docker"
dockerfile = "Dockerfile.service-b"
target = "release"
contexts = {
base-image = "target:service-a"
}
}
More info: https://docs.docker.com/build/bake/build-contexts/ |
Contributing guidelines
I've found a bug and checked that ...
Description
I'm using docker-compose.yml to setup two services. Let's name them service-a and service-b for simplicity.
service-a builds an image that's required to build the dockerfile for service-b by using
FROM service-a
.FROM registry.local.docker/service-a:local AS release
2nd try using additional-contexts & base-image
FROM base-image AS release
Expected behaviour
I would expect that docker-compose build for service-b will load the docker-host image tagged as
registry.local.docker/service-a
into the buildx build for service-b making the image available.Actual behaviour
Running
docker-compose build
will break-off trying to build the service-b with error:The image is available on docker-host. This has been checked using
docker image ls | grep service-a
which lists the service-a image correctly tagged asregistry.local.docker/service-a
.Even trying to add build.additional_contexts for base-image and using base-image instead of the image-name itself won't work.
Buildx version
github.com/docker/buildx v0.11.2 9872040
Docker info
Builders list
Configuration
I've made a reproducer basing on simple alpine image (without any real service):
https://github.com/Gabriel-Kaufmann/reproducer-docker-compose-buildx-issue
Build logs
Additional info
I've tested using local docker registry:v2 image and build still fails. In my opinion build should work with and without external registry also trying to provide local docker images from host (where buildx runs).
service-a image is loaded into my docker image-storage! But funny fact... it's always shown with "age 3 weeks" even when I've been running a fresh build only 1 minute ago (and deleted the old image before):
And finally regardeless of adding
--push --pull
to docker-compose build and also providing x-bake load/push attributes in docker-compose.yml the registry is NOT pushed to my local registry. It's only available in my docker host image-storage.This should take care of that the image(s) are provided to buildx (regardeless if registry or docker image-storage), but it doesn't work as documentated and expected.
The text was updated successfully, but these errors were encountered: