Skip to content

fix: restore post-connect fallback for multi-network stacks on API < 1.44#13629

Open
jotka wants to merge 2 commits intodocker:mainfrom
jotka:fix/multi-network-old-daemon-compat
Open

fix: restore post-connect fallback for multi-network stacks on API < 1.44#13629
jotka wants to merge 2 commits intodocker:mainfrom
jotka:fix/multi-network-old-daemon-compat

Conversation

@jotka
Copy link

@jotka jotka commented Mar 9, 2026

Problem

Docker Compose 5.1.0 broke multi-network stacks on Docker daemons older than API 1.44 (Docker Engine < 23.0), including Synology DSM 7.1 (API 1.41) and DSM 7.2 (API 1.43). The error is:

Container cannot be connected to network endpoints

This is a regression from 5.0.2 which worked correctly on these daemons.

Closes #13628

Context

I maintain Dockhand, a Docker management application. Many of our users run Dockhand on Synology NAS devices (DSM 7.1/7.2), which ship with Docker 20.10 (API 1.41). This regression broke multi-network stack deployments for all of them when we updated docker-compose to 5.1.0. We had to cap docker-compose at 5.0.2 as a workaround while investigating the root cause.

Root Cause

Both regressions were introduced in commit bfb5511 (go.mod: bump github.com/moby/moby/api v1.53.0, moby/client v0.2.2):

1. defaultNetworkSettings() in create.go

The versions.GreaterThanOrEqualTo(version, APIVersion144) guard was removed during the moby API bump, making defaultNetworkSettings unconditionally include ALL networks in EndpointsConfig for ContainerCreate. Old daemons (< API 1.44) only accept a single entry and reject the request with the error above.

2. The post-connect fallback was removed from convergence.go

The same commit removed the NetworkConnect fallback loop from createMobyContainer(). Previously (since aaa7ef6), after ContainerCreate, the code checked versions.LessThan(apiVersion, "1.44") and connected extra networks one-by-one via NetworkConnect(). This entire block was dropped during the API migration.

Fix

First commit (4f14ab8): Restore backward compat

Restores the two behaviors from 5.0.2:

  1. create.godefaultNetworkSettings(): Only include extra networks in EndpointsConfig when apiVersion >= 1.44 (guarded by !versions.LessThan(version, apiVersion144)).

  2. convergence.gocreateMobyContainer(): Restore the post-connect fallback. After container creation, when apiVersion < 1.44, iterate the service's extra networks and call NetworkConnect() for each, skipping the primary network (already configured via NetworkMode in ContainerCreate).

Second commit (7895a5a)

  1. Pass APIVersion through createConfigs: Added APIVersion field to the createConfigs struct, populated from the existing apiVersion local in getCreateConfigs(). This eliminates the redundant s.RuntimeVersion(ctx) call in createMobyContainer.

  2. Reorder ContainerInspect after NetworkConnect: Moved the inspect call after the NetworkConnect loop so the returned container.Summary includes all attached networks.

  3. Unit tests for the < 1.44 code path:

    • TestDefaultNetworkSettings sub-test with version "1.43" — asserts EndpointsConfig contains only the primary network.
    • TestCreateMobyContainerLegacyAPI — asserts ContainerCreate gets only the primary network, NetworkConnect is called for the secondary, and ContainerInspect runs after NetworkConnect.

Testing

  • Unit tests pass (the TestRunHook_ConsoleSize failure is a pre-existing PTY crash on macOS/arm64, unrelated to this change and present on main before this fix)
  • Tested manually against Docker 20.10 (API 1.41) — multi-network stacks now deploy correctly
  • No regression expected on modern daemons (API >= 1.44): they continue to use the multi-endpoint ContainerCreate path

@jotka jotka requested a review from a team as a code owner March 9, 2026 15:34
@jotka jotka requested review from glours and ndeloof March 9, 2026 15:34
…1.44

Docker Compose 5.1.0 broke multi-network stacks on Docker daemons older
than API 1.44 (Docker < 23.0, e.g. Synology DSM 7.1/7.2) with error:
  "Container cannot be connected to network endpoints"

Root cause: defaultNetworkSettings() was refactored to unconditionally
include ALL networks in EndpointsConfig for ContainerCreate, without the
API version guard that limited this to daemons >= 1.44. The post-connect
NetworkConnect() fallback that handled old daemons was also removed.

Fix:
- In defaultNetworkSettings() (create.go): only add extra networks to
  EndpointsConfig when apiVersion >= 1.44
- In createMobyContainer() (convergence.go): restore the post-connect
  fallback that calls NetworkConnect() for each extra network when
  apiVersion < 1.44

Fixes docker#13628

Signed-off-by: jarek <jkrochmalski@gmail.com>
@jotka jotka force-pushed the fix/multi-network-old-daemon-compat branch 2 times, most recently from 8f5763e to af22a2b Compare March 9, 2026 16:45
- Add APIVersion field to createConfigs so createMobyContainer can
  use the version already fetched by getCreateConfigs instead of
  calling RuntimeVersion a second time.
- Move ContainerInspect after the NetworkConnect loop so the
  returned container.Summary includes all attached networks.
- Add unit tests for the < 1.44 code path in both
  defaultNetworkSettings and createMobyContainer.

Signed-off-by: Jarek Krochmalski <jkrochmalski@gmail.com>
@jotka jotka force-pushed the fix/multi-network-old-daemon-compat branch from af22a2b to 7895a5a Compare March 9, 2026 16:47
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.

[bug] regression from 5.02 - multi-network stacks broken on Docker API < 1.44 (regression in v5.1.0)

1 participant