Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sugizo opened this issue Jan 21, 2024 · 5 comments

Comments

@sugizo
Copy link

sugizo commented Jan 21, 2024

env
google colab

steps

!apt update
!apt install -y docker.io
pip install -U docker
import docker

execute

client = docker.from_env()
client

result

FileNotFoundError                         Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py](https://localhost:8080/#) in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    790             # Make the request on the HTTPConnection object
--> 791             response = self._make_request(
    792                 conn,

29 frames
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

ProtocolError                             Traceback (most recent call last)
ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

The above exception was the direct cause of the following exception:

DockerException                           Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/docker/api/client.py](https://localhost:8080/#) in _retrieve_server_version(self)
    218             ) from ke
    219         except Exception as e:
--> 220             raise DockerException(
    221                 f'Error while fetching server API version: {e}'
    222             ) from e

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

best regards

@aaraney
Copy link

aaraney commented Jan 25, 2024

Seems like a duplicate of #3198.

If you can shell out and have access to the docker cli, you can use docker context inspect $(docker context show) | awk -F '"' '/"Host"/ {print $4}' to get current docker daemon host endpoint. Set that to the DOCKER_HOST environment variable and you should be good to go.

@sugizo
Copy link
Author

sugizo commented Jan 26, 2024

still not work, already tried
execute
!docker context inspect $(docker context show) | awk -F '"' '/"Host"/ {print $4}'

result
unix:///var/run/docker.sock

trial 1
execute

%env DOCKER_HOST='unix:///var/run/docker.sock'
docker.from_env()

result

DockerException                           Traceback (most recent call last)
[<ipython-input-20-c914c82b5046>](https://localhost:8080/#) in <cell line: 1>()
----> 1 docker.from_env()

3 frames
[/usr/local/lib/python3.10/dist-packages/docker/utils/utils.py](https://localhost:8080/#) in parse_host(addr, is_win32, tls)
    285         if port <= 0:
    286             if proto != 'ssh':
--> 287                 raise errors.DockerException(
    288                     f'Invalid bind address format: port is required: {addr}'
    289                 )

DockerException: Invalid bind address format: port is required: 'unix:///var/run/docker.sock'

trial 2
execute

%env DOCKER_HOST='unix:///var/run/docker.sock:2376'
docker.from_env()

result

DockerException                           Traceback (most recent call last)
[<ipython-input-22-c914c82b5046>](https://localhost:8080/#) in <cell line: 1>()
----> 1 docker.from_env()

3 frames
[/usr/local/lib/python3.10/dist-packages/docker/utils/utils.py](https://localhost:8080/#) in parse_host(addr, is_win32, tls)
    285         if port <= 0:
    286             if proto != 'ssh':
--> 287                 raise errors.DockerException(
    288                     f'Invalid bind address format: port is required: {addr}'
    289                 )

DockerException: Invalid bind address format: port is required: 'unix:///var/run/docker.sock:2376'

trial 3
execute

os.environ['DOCKER_HOST'] = 'unix:///var/run/docker.sock'
docker.from_env()

result

FileNotFoundError                         Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/urllib3/connectionpool.py](https://localhost:8080/#) in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, preload_content, decode_content, **response_kw)
    790             # Make the request on the HTTPConnection object
--> 791             response = self._make_request(
    792                 conn,

29 frames
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

ProtocolError                             Traceback (most recent call last)
ProtocolError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))

The above exception was the direct cause of the following exception:

DockerException                           Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/docker/api/client.py](https://localhost:8080/#) in _retrieve_server_version(self)
    218             ) from ke
    219         except Exception as e:
--> 220             raise DockerException(
    221                 f'Error while fetching server API version: {e}'
    222             ) from e

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

thanks and best regards

@heyLQ
Copy link

heyLQ commented Feb 16, 2024

how do I solve this problem on a server if I don't have sudo permission?

@weders
Copy link

weders commented Mar 28, 2024

The dashboard approach solved it for me on a Mac:

https://devops.stackexchange.com/questions/15602/mac-m1-docker-desktop-no-longer-launches

I.e, do the following steps:

  1. Open the docker dashboard
  2. Go to settings / advanced
  3. Check the box "Allow the default Docker socket to be used (requires password)"
  4. Restart

@Merikanto
Copy link

Ran into this issue as well.

Another solution for Mac user is to use Colima - https://github.com/abiosoft/colima
Which will allow the client to use the socket unix://${HOME}.colima/default/docker.sock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants