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

if you scroll up in the exception stack trace and see:

sock.connect(self.unix_socket)
urllib3.exceptions.ProtocolError: (‘Connection aborted.’, FileNotFoundError(2, ‘No such file or directory’))

then the python sdk cannot connect to the socket it uses to communicate with docker desktop. It can be fixed by running docker context ls and setting DOCKER_HOST through something like this:

export DOCKER_HOST=unix:///home/USERNAME/.docker/desktop/docker.sock

good luck!

1 Like