Skip to content

feat: fallback to default socket address when docker.from_env() fails #832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

GaetanLepage
Copy link

New Container

Context: bumping testcontainers in nixpkgs (NixOS/nixpkgs#417242)

When importing testcontainers in the nix sandbox, where Docker is not available, the code now fails with:

docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')

This is because this call to docker.from_env() fails.

In the case where this happens, I propose to fall back to the default socket address.

PR Checklist

  • Your PR title follows the Conventional Commits syntax
    as we make use of this for detecting Semantic Versioning changes.
    • Additions to the community modules do not contribute to SemVer scheme:
      all community features will be tagged community-feat,
      but we do not want to release minor or major versions due to features or breaking changes outside of core.
      So please use fix(postgres): or fix(my_new_vector_db): if you want to add or modify community modules.
      This may change in the future if we have a separate package released with community modules.
  • Your PR allows maintainers to edit your branch, this will speed up resolving minor issues!
  • The new container is implemented under modules/*
    • Your module follows PEP 420 with implicit namespace packages
      (if unsure, look at other existing community modules)
    • Your package namespacing follows testcontainers.<modulename>.*
      and you DO NOT have an __init__.py above your module's level.
    • Your module has its own tests under modules/*/tests
    • Your module has a README.rst and hooks in the .. auto-class and .. title of your container
    • Implement the new feature (typically in __init__.py) and corresponding tests.
  • Your module is added in pyproject.toml
    • it is declared under tool.poetry.packages - see other community modules
    • it is declared under tool.poetry.extras with the same name as your module name,
      we still prefer adding NO EXTRA DEPENDENCIES, meaning mymodule = [] is the preferred addition
      (see the notes at the bottom)
  • Your branch is up-to-date (or your branch will be rebased with git rebase)

Preferred implementation

  • The current consensus among maintainers is to try to avoid enforcing the client library
    for the given tools you are triyng to implement.
  • This means we want you to avoid adding specific libraries as dependencies to testcontainers.
  • Therefore, you should implement the configuration and the waiting with as little extra as possible
  • You may still find it useful to add your preferred client library as a dev dependency

@CarliJoy
Copy link
Contributor

Maybe we can just catch all exceptions?
The function should never fail.

@GaetanLepage GaetanLepage requested a review from CarliJoy June 17, 2025 09:41
alexanderankin added a commit that referenced this pull request Jun 23, 2025
…833)

Make configuration monkeypatchable.

Also show users how within readme.

This should also fix the bug in #830 and supersedes #821 and #832

---------

Co-authored-by: David Ankin <[email protected]>
@CarliJoy
Copy link
Contributor

I think this MR can be closed. I was superseeded by #833

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.

3 participants