testcontainers-python icon indicating copy to clipboard operation
testcontainers-python copied to clipboard

Bug: Error while fetching server API version

Open Goldziher opened this issue 11 months ago • 9 comments

Describe the bug

The library is raising a DockerException when trying to fetch the server version. I saw multiple older issues related to this issue, but it's now repeating.

To Reproduce

def create_container():
    container = PostgresContainer("pgvector/pgvector:pg17", driver=None)
    container.start()

Runtime environment

  • M1 Pro
  • Python 3.12.8
  • Docker Desktop 4.37.2 (179585)
  • Testcontainers 4.9.0 installed via uv

Results of running docker context ls:

NAME              DESCRIPTION                               DOCKER ENDPOINT                                          ERROR
default           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
desktop-linux *   Docker Desktop                            unix:///Users/naamanhirschfeld/.docker/run/docker.sock

Goldziher avatar Jan 09 '25 08:01 Goldziher

Same issue for M3 chip, Docker desktop 4.37.1 testcontainers 4.9.0 installed via poetry. Same output from docker context ls

techanfa avatar Jan 12 '25 23:01 techanfa

My guess is that this is happening with one of the components maintained by docker, either docker desktop or the python docker client, we don't really have docker desktop in the cicd, it's not so easy to install there. I'll try to take a look if it's that, see if upgrading the python docker client helps, in case it's not the latest or something. There have been instances of python requests library causing issues as well

alexanderankin avatar Jan 13 '25 04:01 alexanderankin

My guess is that this is happening with one of the components maintained by docker, either docker desktop or the python docker client, we don't really have docker desktop in the cicd, it's not so easy to install there. I'll try to take a look if it's that, see if upgrading the python docker client helps, in case it's not the latest or something. There have been instances of python requests library causing issues as well

Thank you. I reinstalled docker desktop, cleaned everything up, and restarted, and... It magically resolved.

I hate it when things are so obscure, but at least my tests are passing again.

I imagine it is something in docker desktop that is fucking things up.

Weirdly though, I was able to communicate with docker normally even when the test container library was not.

Goldziher avatar Jan 13 '25 06:01 Goldziher

Same issue, had to reinstall docker desktop after macos Sequoia update.

jacobmiller22 avatar Jan 13 '25 17:01 jacobmiller22

I've also managed to fix the same issue by re-installing Docker after a Mac update. Maybe this issue can be closed since it doesn't seem to be caused by testcontainers itself.

laurens-teirlynck avatar Feb 11 '25 10:02 laurens-teirlynck

I compared the locations of the .sock files of both pre-configured contexts between my system and the one of a colleague who doesn't have this issue. For him there's a symbolic link from /var/run/docker.sock (default context) to ~/.docker/run/docker.sock (linux-desktop context) which is missing from my system.

I manually created it on my machine via sudo ln -s ~/.docker/run/docker.sock /var/run/docker.sock which fixes the issue. No re-install needed.

levrik avatar Apr 01 '25 08:04 levrik

I switched to using colima, and test-containers completely fails.

Goldziher avatar Apr 01 '25 08:04 Goldziher

@levrik solution works

There was issues with testcontainers not capable of finding the docker socket if it was not in the traditional path /var/run/docker.sock

It was recently fixed here: https://github.com/testcontainers/testcontainers-python/commit/6817582bf67ed36448b69019ab897c50ae80e7e1 it might work out of the box since this change, but it has not yet been released

vemonet avatar Apr 28 '25 13:04 vemonet

For better triaging and debugging (for users, but also us maintainers), it seems useful to fail with a clearer error message, if there are issues when communicating (or even finding) the right Docker socket.

kiview avatar Apr 28 '25 15:04 kiview