-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Referencing local image name fails on "docker compose build" #8538
Comments
I realize this is probably because of the parallelism that is part of the |
It seems to me this indeed only works "by chance" as I'm not sure if/how we can support such a use-case, would need to check how buildkit can handle this. |
I'm facing this issue too. Is it possible to analyze the build dependency by marking possibly used as base image against the images which specify both |
Having this issue as well. I tried defining |
IMO this is what A lot of people depend on this behaviour being the same when moving to V2. A workaround I see is manually building the images in @ndeloof This issue is breaking behaviour in a lot of repos I'm seeing and should be addressed. |
Same issue applies to compose v1 as long as buildkit is enabled: #8449 |
depends on docker/buildx#447 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still on it |
This issue has been automatically marked as not stale anymore due to the recent activity. |
Apparently similar to #8805 |
Are there any temporary work arounds for this problem? |
Workarounds depend a bit on your exact use-case; You can run the builds for each service manually to make sure to build the base image first ( The other workaround (this would usually be the recommended approach) is to use a multi-stage build. However, this assumes the situation as outlined in this ticket's description where both images share the same build-context. Rewriting the example to have both services use the same Dockerfile, but a different # docker/docker-compose.yml
services:
base:
image: neilyio/base
build:
context: .
target: base
extended:
build:
context: .
target: extended # syntax=docker/dockerfile:1
FROM scratch AS base
COPY README.md /root/README.md
FROM base AS extended
CMD cat /root/README.md It's worth noting that; When building only docker compose build extended
[+] Building 2.9s (9/9) FINISHED
=> [internal] load build definition from Dockerfile 0.2s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.3s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 2.0s
=> CACHED docker-image://docker.io/docker/dockerfile:1@sha256:443aab4ca21183e069e7d8b2dc68006594f40bddf1b15bbd83f5137bd93e80e2 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> [internal] load .dockerignore 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 30B 0.0s
=> CACHED [base 1/1] COPY README.md /root/README.md 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:ee813e9db95b2b2d222f4cf72b4507ece85773201a26634f5066ff7d2d4bec65 0.0s
=> => naming to docker.io/library/compose-multibuild_extended 0.0s
docker image ls --filter reference=neilyio/base
REPOSITORY TAG IMAGE ID CREATED SIZE
docker compose build base
[+] Building 1.4s (9/9) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 32B 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 0.8s
=> CACHED docker-image://docker.io/docker/dockerfile:1@sha256:443aab4ca21183e069e7d8b2dc68006594f40bddf1b15bbd83f5137bd93e80e2 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> [internal] load .dockerignore 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 30B 0.0s
=> CACHED [base 1/1] COPY README.md /root/README.md 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:67e08e818eb01fd3b97ad637b5e99762d34c766e2bb11f2c501a716ef183de62 0.0s
=> => naming to docker.io/neilyio/base 0.0s Generally, building docker inspect --format '{{json .RootFS.Layers}}' neilyio/base
["sha256:3b1be5298307e60029517bf38caa3f1b58121ef39d56d832b4a62dbabc56c3d3"]
docker inspect --format '{{json .RootFS.Layers}}' compose-multibuild_extended
["sha256:3b1be5298307e60029517bf38caa3f1b58121ef39d56d832b4a62dbabc56c3d3"] |
@thaJeztah thank you for the detailed response. From what I've been reading online, it was my conclusion too. My situation is tad more dependency chain problematic, where I'm building a Any idea on ETA / priority for this issue? Thanks again. |
@curlybeast Recent docker compose release will build images with respect to the |
Not sure if this valid or not, but I have same issue and I solve it by using this 2 commands :
After i run that I re-run docker-compose up/build and its solved. |
Thanks for letting me know about this. Which version is this released in? |
for me this is fixed when i start use |
Just be careful you don't have another version in your |
To better cover this scenario, it seems to be we should define a new depends_on condition dedicated to build requirements, i.e. services:
base:
build: .
extened:
build:
context: extended
depends_on:
base:
condition: image_built I'll experiment with this approach and prepare a proposal on https://github.com/compose-spec/compose-spec |
Any updates on this issue? It seems like docker compose v2.18.1 doesn't respect depends_on for the build when build kit is enabled. |
@pebo can you provide a simple example to reproduce this issue? |
@ndeloof It seems like the problem arises when the dependent service is using the Dockerfile FROM alpine as base
RUN echo 'foo' > /foo.txt
RUN echo 'sleeping for 10s' && sleep 10
FROM base-image as sub
RUN echo 'bar' > /bar.txt && cat /foo.txt >> /bar.txt docker-compose.ml version: "3"
services:
base:
image: base-image
build:
context: .
dockerfile: ./Dockerfile
target: base
deploy:
replicas: 0
sub-with-build:
build:
context: .
dockerfile: ./Dockerfile
target: sub
command: echo 'sub-with-build' && cat /bar.txt
depends_on:
- base
sub-with-image:
image: base-image
command: echo 'sub-with-image' && cat /bar.txt
depends_on:
- base Error docker compose up
[+] Running 2/2
✘ sub-with-image Error The service |
@pebo Can confirm this. I had one base image and it was working. Then tried adding a second "stage" (since a few images share part of the features) and suddenly everything fell apart. |
Some folks have noted that |
Even though undocumented, |
Be careful when using buildkit features. Buildkit uses dockerized build-instances and therefore this instances have some isolation against host system (and host docker). I did not realize at first, what consequences that can have. If you have two docker-compose services with services that depend on base-image build by another service this can break if you are using separate Dockerfiles! |
|
…hp-fpm-base` and passing args to prevent double escaping dockerfile variables in compose: docker/docs#18566 (comment) * move the value of env `PHP_INI_OPEN_BASEDIR` from `common.compose.yaml` to `php-fpm/compose.yaml` as `build.args` - remove all service-level key `depends_on: [php-fpm]` as it won't specify building order: docker/compose#8538 (comment) docker/compose#5228 (comment)
…hp-fpm-base` and passing args to prevent double escaping dockerfile variables in compose: docker/docs#18566 (comment) * move the value of env `PHP_INI_OPEN_BASEDIR` from `common.compose.yaml` to `php-fpm/compose.yaml` as `build.args` - remove all service-level key `depends_on: [php-fpm]` as it won't specify building order: docker/compose#8538 (comment) docker/compose#5228 (comment)
Description
I'm getting an error from
docker compose build
with a setup that is consistently successful withdocker-compose build
.I have a
docker-compose.yml
file with two services:base
andextended
.base.image
gives a name to the image built bybase
, and I'd like to use that name as theFROM
image in the Dockerfile for theextended
service.This works well with
docker-compose build
. It does not work withdocker compose build
.Steps to reproduce the issue:
docker/
folder with these three files, plus an emptyREADME.md
.cd
intodocker/
.docker-compose build
, expect a successful run.docker compose build
, expect a failure.Describe the results you received:
docker compose build
produces:Describe the results you expected:
I expected
docker compose build
to find the locally-builtneilyio/base
image, instead it seems to try and load fromdocker.io/neilyio/base:latest
. I expecteddocker compose build
to have the same behaviour asdocker-compose build
, which successfully found the local image.Additional information you deem important (e.g. issue happens only occasionally):
This can be a little tricky to reproduce because of Docker's caching.
docker compose build
will work fine ifneilyio/base
is already built.docker compose build
will successfully find the local image, so it can give the impression that it's working. My step 3 above, clearing the cache, is important to accurately reproduce this. I found I needed to do both asystem prune
andimage rm
for this.docker-compose build
works every time, whether or notneilyio/base
has been built before.Output of
docker version
:Output of
docker context show
:Output of
docker info
:Additional environment details (AWS ECS, Azure ACI, local, etc.):
Local run on M1 Macbook Air.
The text was updated successfully, but these errors were encountered: