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

I have installed docker on M1 chip in Rosatta mode and Docker daemon is also running. When I try to execute docker.from_env() in my python code I’m getting this error
“docker.errors.DockerException: Error while fetching server API version: (‘Connection aborted.’, FileNotFoundError(2, ‘No such file or directory’))”

Can someone help to resolve this issue? I tried reinstalling the docker multiple times and my docker is upto date also.

I think docker is not running or doesn’t have enough permissions.
If you are using Docker Desktop, try launching the application.
Check to see if the user running Python can use docker commands

Hello,
I have installed the same docker in M1 and I can make it work. please follow the below steps,

  1. make sure you have docker installed on the system and verify
    Screenshot 2023-04-22 at 12.46.33 PM

  2. run

docker info

expected result (redacted)

 Name: docker-desktop
 ID: 2B2V:VF6G:NA67:VXNS:HG67:NOLE:UGRL:BTCF:56EC:ZT3E:C7NU:4JET
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false
  1. below example Python code
pip install docker
import docker
client = docker.from_env()
res= client.containers.run("ubuntu", "echo hello world")
print("Running",res)
  1. Result
Running b'hello world\n'

@alishah730 I have similar setup as yours in the info but the error persists.

Hi,
Under advanced settings check the case “Allow the default Docker socket to be used (requires password)”.

1 Like

Thank you @zandolsi, that worked.