Skip to content

[BUG] docker compose run triggers an unwanted rebuild (regression in v2.37.2) #12966

Closed

Description

@Tycale

Description

Affected versions

Component Works (v2.37.1) Fails (v2.37.2)
Docker Compose ✅ ❌

Since Docker Compose v2.37.2, docker compose run seems to always rebuilds a service that has both an image: tag and a build: section, even when the tagged image is already present locally. Earlier versions (≤ v2.37.1) correctly skipped the build. This regression breaks CI pipelines that pre-build images with secret build args and expect the run phase to start the container without rebuilding.

Steps To Reproduce

Steps to reproduce

# 1 – Build and load the image locally
docker buildx build \
  --load \
  -f src/path/Dockerfile.api-core \
  --target base \
  -t X-api .

# 2 – docker-compose.yml
cat <<'YML' > docker-compose.yml
services:
  core-test:
    image: X-api          # Matches the tag built above
    build:
      context: .
      dockerfile: src/path/Dockerfile.api-core
      target: base
YML

# 3 – Run the service
docker compose run --rm core-test echo OK

Expected behavior (v2.37.1)

docker compose run detects the local image X-api and starts the container without any build.

Actual behavior (v2.37.2)

Compose always launches a new build for core-test.

Why is it an issue ?

In my CI, it fails because secret build-args (e.g. Y_SECRET) are only available during the initial build step.

Compose Version

/

Docker Environment

## Env
Docker version

/usr/bin/docker version
  Client:
   Version:           25.0.4
   API version:       1.44
   Go version:        go1.21.8
   Git commit:        1a576c5
   Built:             Wed Mar  6 16:32:02 2024
   OS/Arch:           linux/amd64
   Context:           default
  Server: Docker Engine - Community
   Engine:
    Version:          28.2.2
    API version:      1.50 (minimum version 1.24)
    Go version:       go1.24.3
    Git commit:       45873be
    Built:            Fri May 30 11:52:20 2025
    OS/Arch:          linux/amd64
    Experimental:     false
   containerd:
    Version:          v1.7.27
    GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
   runc:
    Version:          1.2.6
    GitCommit:        v1.2.6-0-ge89a[29](https://github.com/PII/PII/actions/runs/15829363608/job/44617836286?pr=26309#step:7:31)9
   docker-init:
    Version:          0.19.0
    GitCommit:        de40ad0
  /usr/bin/docker info
  Client:
   Version:    25.0.4
   Context:    default
   Debug Mode: false
   Plugins:
    buildx: Docker Buildx (Docker Inc.)
      Version:  v0.13.1
      Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
    compose: Docker Compose (Docker Inc.)
      Version:  v2.37.1
      Path:     /home/runner/.docker/cli-plugins/docker-compose
  Server:
   Containers: 1
    Running: 1
    Paused: 0
    Stopped: 0
   Images: 1
   Server Version: 28.2.2
   Storage Driver: overlay2
    Backing Filesystem: xfs
    Supports d_type: true
    Using metacopy: false
    Native Overlay Diff: true
    userxattr: false
   Logging Driver: json-file
   Cgroup Driver: cgroupfs
   Cgroup Version: 2
   Plugins:
    Volume: local
    Network: bridge host ipvlan macvlan null overlay
    Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
   CDI spec directories:
    /etc/cdi
    /var/run/cdi
   Swarm: inactive
   Runtimes: runc io.containerd.runc.v2
   Default Runtime: runc
   Init Binary: docker-init
   containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
   runc version: v1.2.6-0-ge89a299
   init version: de40ad0
   Security Options:
    seccomp
     Profile: builtin
    cgroupns
   Kernel Version: 6.1.134
   Operating System: Alpine Linux v3.22 (containerized)
   OSType: linux
   Architecture: x86_64
   CPUs: 16
   Total Memory: [30](https://github.com/PII/PII/actions/runs/15829363608/job/44617836286?pr=26309#step:7:32).79GiB
   Name: arc-runner-set-amd64-8c-zjfb5-runner-nhv7m
   ID: cb10c906-1723-4f6d-9863-8f6679a61d67
   Docker Root Dir: /var/lib/docker
   Debug Mode: false
   Username: charlessortlist
   Experimental: false
   Insecure Registries:
    ::1/128
    127.0.0.0/8
   Live Restore Enabled: false
   Product License: Community Engine
  WARNING: bridge-nf-call-iptables is disabled

Anything else?

Thanks for your time, and for maintaining this awesome product!

Activity

  1. glours commented on Jun 23, 2025

    @glours
    Contributor

    Seems to be a duplicate of #12965

  2. Tycale commented on Jun 23, 2025

    @Tycale
    Author

    Maybe related, both regressions appeared in v2.37.2, but the visible effect is different:
    • My report : docker compose run rebuilds the service when an image: already exists (image + build section).
    • #12965 : the container isn’t removed after --rm.

    So they might share the same root cause, but the impact (unwanted rebuild vs. leftover container) is not the same.

  3. self-assigned this
    on Jun 23, 2025
  4. ndeloof commented on Jun 24, 2025

    @ndeloof
    Contributor

    I can't reproduce:

    $ docker buildx build -t toto .
    [+] Building 1.1s (6/6) FINISHED                                                                   docker:desktop-linux
    ...
     => => unpacking to docker.io/library/toto:latest                                                                  0.0s
    
    $ cat compose.yaml 
    services:
      test:
        image: toto
        build: .
    
    $ docker compose run --rm test echo OK
    [+] Creating 1/1
     ✔ Container tmp-test-1  Created                                                                                   0.0s 
    OK
    
  5. glours commented on Jun 24, 2025

    @glours
    Contributor

    Hello @Tycale
    We just merged a fix for multiples regressions with run command, you can build a custom version from the main branch or use the binary for your platform available at the bottom of this page and let me know if you still have the issue?

  6. Tycale commented on Jun 24, 2025

    @Tycale
    Author

    Thanks a lot 💯, I am on it !

  7. Tycale commented on Jun 24, 2025

    @Tycale
    Author

    Tested the binary in my CI: no rebuild, everything passes ! All good now 🥳

    Thanks for the quick fix! 🎉

  8. ndeloof commented on Jun 24, 2025

    @ndeloof
    Contributor

    Closing as "fixed by #12968"

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions