Skip to content

[BUG] runing a service builds its depends-ons twice when pull policy is build #13323

Closed

Description

@luciangabor

Description

Please see the steps to reproduce

Steps To Reproduce

With a compose.yaml like this:

services:
  nginx:
    pull_policy: build
    build:
      dockerfile_inline: |
          FROM nginx
          # this is used as "marker" of time spent during builds
          ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo
    healthcheck:
      test: curl -fs localhost
      start_interval: 1s
      start_period: 10s

  curl:
    image: alpine/curl
    depends_on:
      nginx:
        condition: service_healthy
    command: curl -fsI nginx

docker compose run curl will produce the following output:

[+] Building 5.7s (10/10) FINISHED                                                                                                                                                            
 => [internal] load local bake definitions                                                                                                                                               0.0s
 => => reading from stdin 605B                                                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 186B                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/nginx:latest                                                                                                                          1.4s
 => [auth] library/nginx:pull token for registry-1.docker.io                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo                                                                                               3.9s
 => [1/2] FROM docker.io/library/nginx:latest@sha256:029d4461bd98f124e531380505ceea2072418fdf28752aa73b7b273ba3048903                                                                    0.0s
 => CACHED [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo                                                                                        0.0s
 => exporting to image                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                  0.0s
 => => writing image sha256:94163b15c51df0859e7f02f29c07aa61618af9de589b579b1c73c951c9772ccd                                                                                             0.0s
 => => naming to docker.io/library/run-nginx                                                                                                                                             0.0s
 => resolving provenance for metadata file                                                                                                                                               0.0s
[+] Creating 3/3
 ✔ run-nginx              Built                                                                                                                                                          0.0s 
 ✔ Network run_default    Created                                                                                                                                                        0.1s 
 ✔ Container run-nginx-1  Created                                                                                                                                                        0.1s 
[+] Running 1/1
 ✔ Container run-nginx-1  Started                                                                                                                                                        0.3s 
[+] Building 3.6s (9/9) FINISHED                                                                                                                                                              
 => [internal] load local bake definitions                                                                                                                                               0.0s
 => => reading from stdin 605B                                                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 186B                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/nginx:latest                                                                                                                          0.3s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo                                                                                               2.9s
 => [1/2] FROM docker.io/library/nginx:latest@sha256:029d4461bd98f124e531380505ceea2072418fdf28752aa73b7b273ba3048903                                                                    0.0s
 => CACHED [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo                                                                                        0.0s
 => exporting to image                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                  0.0s
 => => writing image sha256:94163b15c51df0859e7f02f29c07aa61618af9de589b579b1c73c951c9772ccd                                                                                             0.0s
 => => naming to docker.io/library/run-nginx                                                                                                                                             0.0s
 => resolving provenance for metadata file                                                                                                                                               0.0s
HTTP/1.1 200 OK
Server: nginx/1.29.2
Date: Tue, 28 Oct 2025 09:22:46 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 07 Oct 2025 17:04:07 GMT
Connection: keep-alive
ETag: "68e54807-267"
Accept-Ranges: bytes

beside the two building stages that are quite visible, adding git repos to an image becomes particularly ... lengthy, with a first [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo 3.9s followed by a second [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo 2.9s (and for other repos times could be a lot bigger)

Compose Version

Docker Compose version v2.40.2

Docker Environment


Anything else?

a docker compose up curl does not lead to two builds:

[+] Building 5.6s (10/10) FINISHED                                                                                                                                                            
 => [internal] load local bake definitions                                                                                                                                               0.0s
 => => reading from stdin 605B                                                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 186B                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/nginx:latest                                                                                                                          1.3s
 => [auth] library/nginx:pull token for registry-1.docker.io                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => [1/2] FROM docker.io/library/nginx:latest@sha256:029d4461bd98f124e531380505ceea2072418fdf28752aa73b7b273ba3048903                                                                    0.0s
 => [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo                                                                                               3.9s
 => CACHED [2/2] ADD --link --keep-git-dir https://github.com/kubernetes/kubernetes.git /big-repo                                                                                        0.0s
 => exporting to image                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                  0.0s
 => => writing image sha256:94163b15c51df0859e7f02f29c07aa61618af9de589b579b1c73c951c9772ccd                                                                                             0.0s
 => => naming to docker.io/library/run-nginx                                                                                                                                             0.0s
 => resolving provenance for metadata file                                                                                                                                               0.0s
[+] Running 4/4
 ✔ run-nginx              Built                                                                                                                                                          0.0s 
 ✔ Network run_default    Created                                                                                                                                                        0.1s 
 ✔ Container run-nginx-1  Created                                                                                                                                                        0.1s 
 ✔ Container run-curl-1   Created                                                                                                                                                        0.1s 
Attaching to curl-1
curl-1  | HTTP/1.1 200 OK
curl-1  | Server: nginx/1.29.2
curl-1  | Date: Tue, 28 Oct 2025 09:34:23 GMT
curl-1  | Content-Type: text/html
curl-1  | Content-Length: 615
curl-1  | Last-Modified: Tue, 07 Oct 2025 17:04:07 GMT
curl-1  | Connection: keep-alive
curl-1  | ETag: "68e54807-267"
curl-1  | Accept-Ranges: bytes
curl-1  | 
curl-1 exited with code 0

Activity

  1. self-assigned this
    on Oct 28, 2025
  2. ndeloof commented on Nov 3, 2025

    @ndeloof
    Contributor

    fixed by #13325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions