compose icon indicating copy to clipboard operation
compose copied to clipboard

Confusion about "docker-compose build" image not tagged correctly

Open typoworx-de opened this issue 3 years ago • 1 comments

After some trying around I'm totally confused about docker-compose.yml using "docker-compose build", whereas the restarted stack doesn't reflect the recent build.

example:


version: '3.5'
services:
  service-dep-foo:
    image: my-registry-tag-name/service-my-app:latest
    build:
      context: .
      dockerfile: Dockerfile.service-my-app

  # Case: This Dockerfile uses "FROM service-dep-foo" as base-image
  service-my-app:
    image: my-registry-tag-name/service-my-app:latest
    build:
      context: .
      dockerfile: Dockerfile.service-my-app

As there seems to be another docker-compose issue with app-build order for services I'm already working-around with a script like this:

services="service-dep-foo service-my-app"

for service in ${services}; do
  COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose \
    build ${service} ${buildArgs[@]}

  [ $? -ne 0 ] && break;
done

Trying to restart the build stack results in "service-my-app" not reflecting the last changes in Dockerfile.

I would expect that the recent build for "service-my-app" is build on top of recent ""service-dep-foo:latest" and the restarted stack is running "service-my-app:latest" whereas the recent build for "service-my-app" is also tagged "latest".

But currently this doesn't seem to work, which also was the decision trying to work-around with a script such above.

Running "docker-compose build" without the script above will result in: ERROR [my-registry-tag-name/service-my-app:latest internal] load metadata for my-registry-tag-name/service-dep-foo:latest

I already found some other developers complaining about this situation but there currently seems to be no clean-solution to fix this. Is there any solution to find a cleaner way for such situations? Why does docker-compose lack a clean solution to respect sorting of service-keys in build-order or some kind of "depends-on" flags for build?

What I would expect: docker-compose build should tag the current service-build immediately with the full name:tag from service.image name. In all my tries to get the build done, all seems to point to the conclusion this is NOT the case.

typoworx-de avatar Jul 25 '22 15:07 typoworx-de

Hi @typoworx-de, thanks for the report!

Did you mean to have the same dockerfile: Dockerfile.service-my-app for both services? In this case, that would create a cyclical dependency as you mention that Dockerfile has a dependency from the other one.

In the case that they are two separate Dockerfiles, is the issue the order of builds? Currently, Compose has no way of defining the build order, or a depends_on for build.

What is the confusion regarding tagging?

laurazard avatar Aug 05 '22 16:08 laurazard

Closing this for now, please reopen an issue with more clarifying information if pertinent.

laurazard avatar Aug 15 '22 09:08 laurazard