Skip to content

fix(up): add Service.containerName helper for explicit container_name#113

Open
YvanY0 wants to merge 1 commit into
Mcrich23:mainfrom
YvanY0:fix/up-respect-container-name
Open

fix(up): add Service.containerName helper for explicit container_name#113
YvanY0 wants to merge 1 commit into
Mcrich23:mainfrom
YvanY0:fix/up-respect-container-name

Conversation

@YvanY0

@YvanY0 YvanY0 commented Jun 21, 2026

Copy link
Copy Markdown

The bug

When a compose file sets an explicit container_name, the container starts correctly — container run --name reads the value. But ComposeUp has three other places that look up the running container by name (waitUntilServiceIsRunning, getIPForRunningService, stopOldStuff), and all three hard-code "\(projectName)-\(serviceName)" instead of reading container_name.

For example, given:

services:
  hermes:
    container_name: hermes

Run from a directory named hermes (no name: field), the container starts as hermes but the post-start poll waits for hermes-hermes and times out:

Error Domain=ContainerWait Code=1 "Timed out waiting for container 'hermes-hermes' to be running."

Issue #38 reported the same bug on the down side; PR #39 fixed ComposeDown.stopOldStuff but ComposeUp was not addressed.

The fix

Extract Service.containerName(projectName:serviceName:) — a single method that encapsulates the rule (prefer explicit container_name, fall back to "\(projectName)-\(serviceName)") — and route all five call sites through it:

  • 4 call sites in ComposeUp (configService, waitUntilServiceIsRunning, getIPForRunningService, stopOldStuff)
  • stopOldStuff in ComposeDown (refactored to use the same helper, replacing the inline if/else from PR Handle compose down with container_name case #39)

When container_name is not set the helper returns the same "\(projectName)-\(serviceName)" string as before; existing compose files without explicit container names are unaffected.

Verification

Tested locally against the compose file above:

Before: container-compose up -d reports Timed out waiting for container 'hermes-hermes' to be running.

After: the container starts and polls successfully with no timeout; container ls -a shows it in running state.

Tests

  • Static: ServiceNamingTests — two unit tests for the pure containerName helper (explicit name wins, default pattern when unset).
  • Dynamic: testUpWithExplicitContainerName — exercises ComposeUp.run() end-to-end with an explicit container_name (mirrors the pattern in PR feat: Providing tests for ComposeDown #50's testUpAndDownContainerName).

Fixes #38

ComposeUp had three places (getIPForRunningService, waitUntilServiceIsRunning,
stopOldStuff) that hard-coded the container name as
"\(projectName)-\(serviceName)" instead of reading service.container_name.
When a compose file set an explicit container_name, the container started
correctly (container run --name used the right value), but the post-start
lookups waited for the wrong name and timed out after 30s.

Extract a single Service.containerName(projectName:serviceName:) helper and
replace all five call sites (four in ComposeUp, one in ComposeDown) with it.
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.

compose down doesn't support named containers (or custom named containers)

1 participant