Python Docker SDK "Error while fetching server API version"

Question:

In the Python Docker SDK, When I do

import docker

docker.from_env()

I see

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

I have docker desktop running and this works in the terminal

$ docker run -it ubuntu

If I add a version number

docker.from_env(version="6.0.1")

it stops erroring, but it doesn’t seem to matter what number I use. I also then see an error on

client.containers.run("ubuntu")

of

requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

I’m on Ubuntu 22.04 and I’m seeing the problem with both Poetry and plain pip + venv. I’ve looked through the dozen or so questions about that error message and tried everything that looked relevant.

Asked By: joel

||

Answers:

My final solution was to uninstall Docker Desktop and install Docker Engine instead. I had to manually delete some Docker config files left over after installation too.

Answered By: joel
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.