fix: restore post-connect fallback for multi-network stacks on API < 1.44#13629
Open
jotka wants to merge 2 commits intodocker:mainfrom
Open
fix: restore post-connect fallback for multi-network stacks on API < 1.44#13629jotka wants to merge 2 commits intodocker:mainfrom
jotka wants to merge 2 commits intodocker:mainfrom
Conversation
…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>
8f5763e to
af22a2b
Compare
- 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>
af22a2b to
7895a5a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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()increate.goThe
versions.GreaterThanOrEqualTo(version, APIVersion144)guard was removed during the moby API bump, makingdefaultNetworkSettingsunconditionally include ALL networks inEndpointsConfigforContainerCreate. 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.goThe same commit removed the
NetworkConnectfallback loop fromcreateMobyContainer(). Previously (since aaa7ef6), afterContainerCreate, the code checkedversions.LessThan(apiVersion, "1.44")and connected extra networks one-by-one viaNetworkConnect(). This entire block was dropped during the API migration.Fix
First commit (
4f14ab8): Restore backward compatRestores the two behaviors from 5.0.2:
create.go—defaultNetworkSettings(): Only include extra networks inEndpointsConfigwhenapiVersion >= 1.44(guarded by!versions.LessThan(version, apiVersion144)).convergence.go—createMobyContainer(): Restore the post-connect fallback. After container creation, whenapiVersion < 1.44, iterate the service's extra networks and callNetworkConnect()for each, skipping the primary network (already configured viaNetworkModeinContainerCreate).Second commit (
7895a5a)Pass
APIVersionthroughcreateConfigs: AddedAPIVersionfield to thecreateConfigsstruct, populated from the existingapiVersionlocal ingetCreateConfigs(). This eliminates the redundants.RuntimeVersion(ctx)call increateMobyContainer.Reorder
ContainerInspectafterNetworkConnect: Moved the inspect call after theNetworkConnectloop so the returnedcontainer.Summaryincludes all attached networks.Unit tests for the < 1.44 code path:
TestDefaultNetworkSettingssub-test with version"1.43"— assertsEndpointsConfigcontains only the primary network.TestCreateMobyContainerLegacyAPI— assertsContainerCreategets only the primary network,NetworkConnectis called for the secondary, andContainerInspectruns afterNetworkConnect.Testing
TestRunHook_ConsoleSizefailure is a pre-existing PTY crash on macOS/arm64, unrelated to this change and present onmainbefore this fix)ContainerCreatepath