Skip to content

Give in-dyno addon containers unique names - #28

Merged
blsmth merged 1 commit into
mainfrom
avoid-container-naming-conflicts-27
Jul 21, 2026
Merged

Give in-dyno addon containers unique names#28
blsmth merged 1 commit into
mainfrom
avoid-container-naming-conflicts-27

Conversation

@blsmth

@blsmth blsmth commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

A client build failed in the prebuild phase with:

FTL Error error="Error response from daemon: Conflict. The container name \"/db\" is already in use by container \"6b84fe4b...\". You have to remove (or rename) that container to be able to reuse that name."

CodeBuild reuses the Docker daemon across builds. The in-dyno test addons (db, redis) were created with fixed container names, so a leftover container from a previous build collides on the next one.

Fix

Prefix the addon container names with the (unique) CodeBuild build ID — the same scheme already used for the buildx builder and the test container. The friendly db/redis names are preserved as network aliases, so other containers can still reach the addon by hostname (e.g. DATABASE_URL=postgres://...@db:5432/postgres).

RunContainer gains an aliases []string parameter; the postbuild test container passes nil (it's already uniquely named).

Testing

Wrote a throwaway integration test against a real Docker daemon:

  • Reproduced the original bug — a second container named db on the same daemon fails with Conflict. The container name "/db" is already in use.
  • Verified the fix — two builds sharing one daemon each start their db addon with unique names (<build-id>-db) and no conflict; the db network alias still resolves (getent hosts db172.19.0.2 db), so DATABASE_URL=...@db:5432 is unaffected.
  • go test ./... passes.

Closes #27

The db/redis test addon containers were created with the fixed names
"db" and "redis". Because CodeBuild reuses the Docker daemon across
builds, a leftover container from a previous build caused a naming
conflict:

  Conflict. The container name "/db" is already in use...

Prefix the addon container names with the (unique) CodeBuild build ID,
matching how the buildx builder and test container are already named.
The friendly "db"/"redis" names are preserved as network aliases so
other containers can still reach the addon by hostname (e.g.
DATABASE_URL=postgres://...@db:5432/postgres).

Closes #27
@blsmth
blsmth merged commit b2ed9a6 into main Jul 21, 2026
7 checks passed
@blsmth
blsmth deleted the avoid-container-naming-conflicts-27 branch July 21, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid container naming conflicts

1 participant