Skip to content

fix: remove stale containers holding project volumes on ddev delete, fixes #8777 - #8950

Merged
rfay merged 1 commit into
ddev:mainfrom
wazum:20261014_wazum_delete_stale_containers
Oct 16, 2026
Merged

rfay merged 1 commit into
ddev:mainfrom
wazum:20261014_wazum_delete_stale_containers

Conversation

@wazum

@wazum wazum commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Short Summary (TL;DR)

ddev delete now removes the stale utility containers that keep a project's database volume busy, and it no longer unregisters the project or reports success when a volume could not be removed.

The Issue

When a ddev start is interrupted, short-lived ddev-utilities containers stay behind with the database volume mounted. They carry an empty com.ddev.site-name label, so ddev delete cannot find them. The volume removal fails with a warning, but the project is unregistered anyway and "Project X was deleted" is printed. The volume is then orphaned and no ddev command can reach it.

How This PR Solves The Issue

Before removing each core volume, Stop() removes every DDEV-labeled container that still mounts it, found with Docker's volume filter. Containers without the com.ddev.platform=ddev label are left alone, so a container the user created is never removed.

The project is unregistered only after all core volumes are gone. If one is still held, Stop() returns an error that names the volume and says the project stays listed, so ddev delete can be run again after the cause is fixed.

The "volume in use" branch in RemoveVolume() compared the whole error string and never matched, so users saw truncated container IDs. It now matches on the wording Docker and Podman use, and prints container names with a docker rm -f hint.

Manual Testing Instructions

ddev utility download-ddev --pr 8950
export PATH="$HOME/tmp/ddev-download-ddev/pr-8950:$PATH"
mkdir ~/tmp/held && cd ~/tmp/held
ddev config --project-type=php --docroot=web
ddev start -y
ddev stop
# Simulate a utility container an interrupted start left behind
docker run --name stale-holder --label com.ddev.platform=ddev --label com.ddev.site-name= -v held-mariadb:/var/lib/mysql ddev/ddev-utilities true
ddev delete -Oy
# Expect "Removing stale container stale-holder using volume held-mariadb", then the volume and the project are gone

To see the retry path, run the docker run line again without the two --label flags and run ddev delete -Oy. Expect an error naming held-mariadb, no "was deleted" line, and the project still in ddev list.

Automated Testing Overview

TestStopRemoveDataRemovesStaleUtilityContainers and TestStopRemoveDataKeepsProjectListedWhenVolumeIsHeld in pkg/ddevapp/delete_test.go create a project volume held by an exited container, with and without the DDEV label, and check the delete and the retry path.

TestRemoveVolumeInUseNamesContainer in pkg/dockerutil/volumes_test.go checks that a held volume produces the error with the container name.

Release/Deployment Notes

ddev delete now exits non-zero and keeps the project listed when a volume could not be removed. Before, it reported success in that case.

…fixes ddev#8777

Stale `ddev-utilities` containers from an interrupted start keep the database volume mounted but carry an empty `com.ddev.site-name` label, so `ddev delete` could not find them. The volume removal failed, yet the project was unregistered and reported as deleted, leaving an orphaned volume.

`Stop()` now removes DDEV-labeled containers that still mount a core volume before removing it, unregisters the project only after all core volumes are gone, and returns an error naming any held volume so `ddev delete` can be run again.

The "volume in use" branch in `RemoveVolume()` compared the whole error string and never matched. It now matches on the Docker and Podman wording and prints container names.
@wazum
wazum requested a review from a team as a code owner October 14, 2026 18:48
@github-actions

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 8950

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Thank you for such a simple reproduction.

@rfay
rfay merged commit 3d9c472 into ddev:main Oct 16, 2026
45 of 46 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in the v1.25.5 release.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ddev delete orphans the database volume when a stale utility container holds it

3 participants