DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
sugizo opened this issue · comments
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
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.
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
how do I solve this problem on a server if I don't have sudo permission?
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:
- Open the docker dashboard
- Go to settings / advanced
- Check the box "Allow the default Docker socket to be used (requires password)"
- Restart