-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Description
Running docker compose up -d --build «container»
in the presence of COMPOSE_BAKE=true
does not re-create the container with the newly-built image. Removing COMPOSE_BAKE
from the environment returns to the original behaviour.
Steps To Reproduce
Scenario
I am using an instance of a customised MariaDB container intended to be the back-end for a Gitea container. Although I haven't tested with different base images, I don't believe that the base image is relevant. MariaDB is simply where I noticed this problem and am able to demonstrate it easily.
Instrumentation
Instrumentation used to demonstrate problem:
-
Health-check script includes:
FORCE_CHANGE=1 echo "Forced change marker = $FORCE_CHANGE"
-
Dockerfile includes:
RUN date >/builddate.txt
This is positioned after the health-check script is copied into the image.
Runtime environment
$ echo $COMPOSE_BAKE
true
$
Test 1
-
Show container not running:
$ docker top gitea_db Error response from daemon: No such container: gitea_db
-
Build container:
$ docker compose up -d --build gitea_db [+] Building 0.5s (11/11) FINISHED => [internal] load local bake definitions 0.0s => => reading from stdin 382B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.16kB 0.0s => [internal] load metadata for ghcr.io/linuxserver/mariadb:latest 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/4] FROM ghcr.io/linuxserver/mariadb:latest 0.0s => [internal] load build context 0.0s => => transferring context: 45B 0.0s => CACHED [2/4] RUN for CNF in /defaults/my.cnf /defaults/custom.cnf ; do [ -f ${CNF} ] && break ; done ; sed -i.bak -e "s/^thread_cache_siz 0.0s => CACHED [3/4] COPY iotstack_healthcheck.sh /usr/local/bin/iotstack_healthcheck.sh 0.0s => CACHED [4/4] RUN date >/builddate.txt 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:e66432205ec39196c2cac3dde2391bbe741af5906b26ba8508127ff3af49f56c 0.0s => => naming to docker.io/library/iotstack-gitea_db 0.0s => resolving provenance for metadata file 0.0s [+] Running 3/3 ✔ gitea_db Built 0.0s ✔ Network iotstack_nextcloud Created 0.1s ✔ Container gitea_db Started 0.6s $
-
Probe instrumentation:
$ docker exec gitea_db cat /builddate.txt Thu Apr 24 01:32:18 UTC 2025 $ docker exec gitea_db iotstack_healthcheck.sh Forced change marker = 1
This is the baseline.
-
Bump counter in health-check script:
FORCE_CHANGE=2 echo "Forced change marker = $FORCE_CHANGE"
-
Rebuild container:
$ docker compose up -d --build gitea_db [+] Building 0.5s (11/11) FINISHED => [internal] load local bake definitions 0.0s => => reading from stdin 382B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.16kB 0.0s => [internal] load metadata for ghcr.io/linuxserver/mariadb:latest 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [1/4] FROM ghcr.io/linuxserver/mariadb:latest 0.0s => [internal] load build context 0.0s => => transferring context: 1.08kB 0.0s => CACHED [2/4] RUN for CNF in /defaults/my.cnf /defaults/custom.cnf ; do [ -f ${CNF} ] && break ; done ; sed -i.bak -e "s/^thread_cache_siz 0.0s => CACHED [3/4] COPY iotstack_healthcheck.sh /usr/local/bin/iotstack_healthcheck.sh 0.0s => CACHED [4/4] RUN date >/builddate.txt 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:a59aa5c348501b84089dd38195edddb1167175750fc0f7b189f216e3b5faa7ac 0.0s => => naming to docker.io/library/iotstack-gitea_db 0.0s => resolving provenance for metadata file 0.0s [+] Running 2/2 ✔ gitea_db Built 0.0s ✔ Container gitea_db Running 0.0s
Note that container is marked "running" rather than being re-created.
-
Probe instrumentation:
$ docker exec gitea_db cat /builddate.txt Thu Apr 24 01:32:18 UTC 2025 $ docker exec gitea_db iotstack_healthcheck.sh Forced change marker = 1
No change from baseline so this is still the prior image that is running.
-
Send another explicit "up":
$ docker compose up -d gitea_db [+] Running 1/1 ✔ Container gitea_db Started 4.1s
Container "Started", as distinct from "Running" at the end of step 5.
-
Probe instrumentation:
$ docker exec gitea_db cat /builddate.txt Thu Apr 24 01:30:47 UTC 2025 $ docker exec gitea_db iotstack_healthcheck.sh Forced change marker = 2
Newly-built image now running.
Revised runtime environment
$ echo $COMPOSE_BAKE
$
Test 2
-
Create initial conditions (steps 1..3 of Test 1):
$ docker top gitea_db Error response from daemon: No such container: gitea_db $ docker compose up -d --build gitea_db Compose can now delegate builds to bake for better performance. To do so, set COMPOSE_BAKE=true. [+] Building 0.9s (10/10) FINISHED docker:default => [gitea_db internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.16kB 0.0s => [gitea_db internal] load metadata for ghcr.io/linuxserver/mariadb:latest 0.0s => [gitea_db internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [gitea_db internal] load build context 0.0s => => transferring context: 1.08kB 0.0s => [gitea_db 1/4] FROM ghcr.io/linuxserver/mariadb:latest 0.0s => CACHED [gitea_db 2/4] RUN for CNF in /defaults/my.cnf /defaults/custom.cnf ; do [ -f ${CNF} ] && break ; done ; sed -i.bak -e "s/^thread_ 0.0s => [gitea_db 3/4] COPY iotstack_healthcheck.sh /usr/local/bin/iotstack_healthcheck.sh 0.1s => [gitea_db 4/4] RUN date >/builddate.txt 0.5s => [gitea_db] exporting to image 0.1s => => exporting layers 0.1s => => writing image sha256:3d783b11bca0626cb88cb08ad48f16f16db5a662e145bc94e68058b1d0cf0f17 0.0s => => naming to docker.io/library/iotstack-gitea_db 0.0s => [gitea_db] resolving provenance for metadata file 0.0s [+] Running 3/3 ✔ gitea_db Built 0.0s ✔ Network iotstack_nextcloud Created 0.1s ✔ Container gitea_db Started 0.5s $ docker exec gitea_db cat /builddate.txt Thu Apr 24 01:51:42 UTC 2025 $ docker exec gitea_db iotstack_healthcheck.sh Forced change marker = 3
-
Bump forced-change marker to 4 and rebuild:
$ docker compose up -d --build gitea_db Compose can now delegate builds to bake for better performance. To do so, set COMPOSE_BAKE=true. [+] Building 0.9s (10/10) FINISHED docker:default => [gitea_db internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.16kB 0.0s => [gitea_db internal] load metadata for ghcr.io/linuxserver/mariadb:latest 0.0s => [gitea_db internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [gitea_db 1/4] FROM ghcr.io/linuxserver/mariadb:latest 0.0s => [gitea_db internal] load build context 0.0s => => transferring context: 1.08kB 0.0s => CACHED [gitea_db 2/4] RUN for CNF in /defaults/my.cnf /defaults/custom.cnf ; do [ -f ${CNF} ] && break ; done ; sed -i.bak -e "s/^thread_ 0.0s => [gitea_db 3/4] COPY iotstack_healthcheck.sh /usr/local/bin/iotstack_healthcheck.sh 0.0s => [gitea_db 4/4] RUN date >/builddate.txt 0.5s => [gitea_db] exporting to image 0.1s => => exporting layers 0.1s => => writing image sha256:9bdb11df90af862a04e93887dc7ffc32f90271825a5eb5e54ac52c6b6ccdc979 0.0s => => naming to docker.io/library/iotstack-gitea_db 0.0s => [gitea_db] resolving provenance for metadata file 0.0s [+] Running 2/2 ✔ gitea_db Built 0.0s ✔ Container gitea_db Started 4.0s $ docker exec gitea_db cat /builddate.txt Thu Apr 24 01:52:29 UTC 2025 $ docker exec gitea_db iotstack_healthcheck.sh Forced change marker = 4
This time the
-d --build
resulted in the newly-built image being instantiated as the running container.
The only difference between tests 1 and 2 is COMPOSE_BAKE
.
Compose Version
$ docker version -f "{{.Server.Version}}"
28.1.1
$ docker compose version
Docker Compose version v2.35.1
$ docker-compose version
Docker Compose version v2.35.1
Docker Environment
Client: Docker Engine - Community
Version: 28.1.1
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.23.0
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.35.1
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 8
Running: 8
Paused: 0
Stopped: 0
Images: 20
Server Version: 28.1.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: local
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
runc version: v1.2.5-0-g59923ef
init version: de40ad0
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.1.21-v8+
Operating System: Debian GNU/Linux 11 (bullseye)
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 3.704GiB
Name: sec-dev
ID: f6406dbb-2fc1-4834-9606-5e826871aec6
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
::1/128
127.0.0.0/8
Live Restore Enabled: false
Anything else?
No response