0

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.

joel
  • 6,359
  • 2
  • 30
  • 55
  • Is there more of the error than that? Are you using Docker Desktop, or just plain Docker? Do you have a `$DOCKER_HOST` environment variable set, or a non-default `docker context`? – David Maze Jan 25 '23 at 14:12
  • @DavidMaze will get more error logs. Docker desktop. re `$DOCKER_HOST` probably not (nothing shows in a fresh terminal). Don't know what the `docker context` is so probably default – joel Jan 25 '23 at 14:47
  • I have a docker context `desktop-linux` in addition to my `default` (if I `docker context list`). Each context has a different endpoint – joel Jan 25 '23 at 15:03
  • This seems the same as [docker/docker-py#3059](https://github.com/docker/docker-py/issues/3059), and that issue suggests a symlink-based workaround. It may be a problem specifically with Docker Desktop 4.13.0. Docker Desktop isn't really necessary on native Linux, though; if you uninstall it and use a non-VM Docker daemon, do things work better? – David Maze Jan 25 '23 at 15:59
  • @DavidMaze that looks likely. I may well remove docker desktop now it's got in the way – joel Jan 25 '23 at 20:36

2 Answers2

1

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.

joel
  • 6,359
  • 2
  • 30
  • 55
0

If you're running MacOS, uninstall Docker using: /Applications/Docker.app/Contents/MacOS/uninstall and then install a fresh version for Docker Desktop. Be sure to choose the appropriate chipset.

devdrc
  • 1,853
  • 16
  • 21