Skip to content

feat(core): support SSH-based DOCKER_HOST#993

Open
Tranquility2 wants to merge 4 commits intomainfrom
support_ssh2
Open

feat(core): support SSH-based DOCKER_HOST#993
Tranquility2 wants to merge 4 commits intomainfrom
support_ssh2

Conversation

@Tranquility2
Copy link
Copy Markdown
Contributor

@Tranquility2 Tranquility2 commented Mar 29, 2026

Fixes #992

Problem

When DOCKER_HOST is set to an SSH URL (e.g. ssh://user@remote-host), the Docker Python SDK rewrites base_url to http+docker://ssh, losing the original hostname. This causes DockerClient.host() to return "ssh" instead of the actual remote address, breaking container connectivity.

Additionally, the SDK defaults to paramiko for SSH connections, which crashes under pytest due to stdin capture conflicts.

Changes

docker_client.py

  • Extract the remote hostname from DOCKER_HOST in host() instead of relying on the SDK's rewritten base_url
  • Default to use_ssh_client=True for SSH connections to avoid paramiko/pytest stdin conflicts
  • Sanitize SSH URLs with unsupported path components before passing to the SDK
  • Add get_docker_host_hostname() and is_ssh_docker_host() helpers

compose.py

  • Handle SSH in PublishedPortModel.normalize() — replace local bind addresses (0.0.0.0, 127.0.0.1, etc.) with the remote SSH hostname

Tests

  • Add SSH-specific tests for DockerClient.host(), connection mode, compose port normalization, and URL sanitization

@Tranquility2 Tranquility2 self-assigned this Mar 29, 2026
@Tranquility2
Copy link
Copy Markdown
Contributor Author

image

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 93.10345% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.47%. Comparing base (2ca2321) to head (1a35b47).

Files with missing lines Patch % Lines
core/testcontainers/core/docker_client.py 93.10% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #993      +/-   ##
==========================================
+ Coverage   78.86%   79.47%   +0.60%     
==========================================
  Files          14       14              
  Lines        1221     1247      +26     
  Branches      142      150       +8     
==========================================
+ Hits          963      991      +28     
+ Misses        216      213       -3     
- Partials       42       43       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

SSH-based DOCKER_HOST not supported

1 participant