Skip to content

fix: mount the engine's Docker socket for a TCP host on Windows - #4119

Open
fiodortretyakov wants to merge 3 commits into
testcontainers:mainfrom
fiodortretyakov:fix-windows-tcp-docker-socket
Open

fiodortretyakov wants to merge 3 commits into
testcontainers:mainfrom
fiodortretyakov:fix-windows-tcp-docker-socket

Conversation

@fiodortretyakov

Copy link
Copy Markdown

What does this PR do?

When the Docker host is a tcp:// endpoint and the client runs on Windows, extractDockerSocketFromClient returns DockerSocketPath. On Windows that variable holds the Docker client's default named pipe (//./pipe/docker_engine, set in init() from client.DefaultDockerHost), so Ryuk gets the pipe path as its bind mount source.

This PR returns WindowsDockerSocketPath (//var/run/docker.sock) for a TCP host on Windows, the same value the Docker Desktop branch already uses. Everything else keeps DockerSocketPath, so nothing changes on Linux and macOS.

  • internal/core/docker_host.go: the TCP case in checkDockerSocketFn.
  • internal/core/docker_host_test.go: the TCP expectations now depend on the platform, and a new subtest emulates a Windows client (GOOS=windows and a named-pipe DockerSocketPath). It fails without the fix.
  • docs/features/configuration.md: rules 1 and 6 mention the Windows path.

Why is it important?

On a Windows machine that talks to a Linux engine over TCP (in my case dockerd in WSL on tcp://localhost:2376 with TLS, no Docker Desktop), the engine receives //./pipe/docker_engine as the bind source, creates it as an empty directory, and Ryuk exits right away. With current main, Run fails after about 20 seconds with reaper: new reaper: run container: started hook: wait until ready: container state: removing: could not start container, after creating 14 Ryuk containers. With v0.44 it waited 60 seconds and left the target container behind in the created state. The only workaround is TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE in every project.

Testcontainers for Java already mounts //var/run/docker.sock for a TCP host on Windows (DockerClientFactory.getRemoteDockerUnixSocketPath).

Related issues

  • None found.

How to test this PR

  • go test ./internal/core/ -run TestExtractDockerSocketFromClient. On main, the new subtest fails on Linux with actual: "//./pipe/docker_engine".
  • On Windows, with DOCKER_HOST=tcp://... pointing to a Linux engine and no override, start any container with Ryuk enabled. Before: the error above. After: Resolved Docker Socket Path: //var/run/docker.sock, one Ryuk container, and my test container was ready after 1.3 seconds.

On Windows, DockerSocketPath holds the client's default named pipe, so a
tcp:// Docker host made Ryuk mount //./pipe/docker_engine and fail. Use
the //var/run/docker.sock UNC path there, as the Docker Desktop branch
already does. Linux and macOS are unchanged.
@fiodortretyakov
fiodortretyakov requested a review from a team as a code owner November 16, 2026 13:29
@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

👷 Deploy request for testcontainers-go pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 43bb9ff

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes
    • Docker TCP connections now resolve to the appropriate engine socket path on Windows and other platforms, ensuring the configured connection uses the expected location.
  • Documentation
    • Clarified that Windows uses //var/run/docker.sock when a Docker host is configured or when the default socket path is used. Other platforms continue to use /var/run/docker.sock.

Walkthrough

TCP Docker hosts now use the Windows socket path on Windows and the standard socket path on other platforms. Tests and configuration documentation describe these platform-specific paths.

Changes

Docker socket path selection

Layer / File(s) Summary
Platform-specific selection and validation
internal/core/docker_host.go, internal/core/docker_host_test.go, docs/features/configuration.md
TCP Docker hosts resolve to the Windows socket path on Windows and the standard path on other platforms. Tests check platform-specific expectations, including a simulated Windows client. Documentation lists the Windows UNC path for the tc.host case and the fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: bug

Suggested reviewers: stevenh

Merge Risk: Minimal · up to 43bb9

On Windows, a TCP Docker host now gets the engine's socket path, so Ryuk no longer receives the client's named pipe as its bind source. Linux and macOS behavior is unchanged. Tests and documentation were updated alongside the change, and I see no remaining merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: for a TCP Docker host on Windows, the Ryuk bind mount now uses the engine's Docker socket path. The PR's code, tests, and docs all match this change. The title does n…
Description check Passed The description explains the problem: a tcp:// host on Windows resolves to the client named pipe, which breaks Ryuk. It names the changed files, gives the fix and the reasoning, and describes how to t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: for a TCP Docker host on Windows, the Ryuk bind mount now uses the engine's Docker socket path. The PR's code, tests, and docs all match this change. The title does not name the Windows-only scope in detail, but it is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description explains the problem: a tcp:// host on Windows resolves to the client named pipe, which breaks Ryuk. It names the changed files, gives the fix and the reasoning, and describes how to test. It matches the changeset and the objectives.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the socket track,
On Windows, paths take a different tack.
The tests confirm which way to go,
The docs make both defaults clear to know.
Then hops away beneath the moon,
With paths in order, neat and soon.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 99fbc91c-0ab9-4753-9124-3f75e854357f
Commits

Reviewing files that changed from the base of the PR and between f311c39 and 43bb9ff.

Files selected for processing: 2

  • docs/features/configuration.md
  • internal/core/docker_host_test.go
Files skipped from review as they are similar to previous changes: 1

  • docs/features/configuration.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@fiodortretyakov

Copy link
Copy Markdown
Author

Reminder: review, Windows TCP host, Ryuk socket mount, mergeable

mdelapenya
mdelapenya previously approved these changes Dec 4, 2026

@mdelapenya mdelapenya 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.

LGTM, thanks for the regression test!

NIT: I'd rename the new subtest to windows-tcp-host to follow our preference for names without spaces?

We’ll wait for CI before merging.

🤖 Written assisted by my Codex

@fiodortretyakov

Copy link
Copy Markdown
Author

Renamed the subtest to windows-tcp-host, as suggested. The two red chroma example jobs (1.26.x and 1.27.x) fail in ExampleChromaContainer_collections while downloading the onnxruntime shared library, which this change does not touch. Could they be re-run once the new commit is through CI?

@mdelapenya

Copy link
Copy Markdown
Member

Renamed the subtest to windows-tcp-host, as suggested. The two red chroma example jobs (1.26.x and 1.27.x) fail in ExampleChromaContainer_collections while downloading the onnxruntime shared library, which this change does not touch. Could they be re-run once the new commit is through CI?

I merged with main so that it gets the Chroma fixes from #4130

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.

2 participants