colima icon indicating copy to clipboard operation
colima copied to clipboard

Python Docker SDK cannot create client from_env

Open adrianmace opened this issue 3 years ago • 8 comments

Description

After switching from Docker Desktop to Colima, tooling written in Python which creates a Docker client using from_env() fails with the following error:

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

Version

Colima Version: 0.4.6 Lima Version: 0.13.0 Qemu Version: 7.1.0

Operating System

  • [X] macOS Intel
  • [ ] macOS M1
  • [ ] Linux

Reproduction Steps

import docker
client = docker.from_env()

Expected behaviour

Client is an instantiated Docker client object.

Additional context

I understand that this is probably not your concern given it is the official Docker Engine SDK that is breaking.

However, given Colima is designed to be an alternative way of running Docker on your workstation it would be great to have a workaround so it can continue to work as a drop-in replacement for Docker Desktop.

adrianmace avatar Nov 08 '22 03:11 adrianmace

Have you tried specifying the DOCKER_HOST environment variable?

export DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"

abiosoft avatar Nov 08 '22 03:11 abiosoft

However, given Colima is designed to be an alternative way of running Docker on your workstation it would be great to have a workaround so it can continue to work as a drop-in replacement for Docker Desktop.

The decision to not override default Docker settings but instead utilise contexts and a different socket is to make it easy for users to try out Colima without breaking their existing workflow.

abiosoft avatar Nov 08 '22 03:11 abiosoft

Thanks for the fast reply! The issue is fixed when I set this and the reason for using contexts makes a lot of sense.

It looks like we'll need to update our tooling to check for both the default location as well as colima default location depending on what our users are using.

Is there a potential future where you allow users the option to force override the default docker settings instead? This is the route we'd likely prefer if we asked our users to make the switch.

Overall I've been trialing this workflow for the last few weeks and absolutely love it! Thanks for some great software 😄

adrianmace avatar Nov 08 '22 03:11 adrianmace

Is there a potential future where you allow users the option to force override the default docker settings instead? This is the route we'd likely prefer if we asked our users to make the switch.

This has been requested a few times now and will be prioritised for the next release.

abiosoft avatar Nov 08 '22 03:11 abiosoft

FYI, the command to override the default socket can be found in the FAQ.

sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock

abiosoft avatar Nov 08 '22 03:11 abiosoft

I'm happy for you to close this with whichever state you think is most appropriate.

Thank you again for the information provided.

adrianmace avatar Nov 08 '22 04:11 adrianmace

Thanks @abiosoft the symlink solves this.

abarrak avatar May 23 '23 11:05 abarrak

Neither of these fixes appear to be helping for Apple M2 Pro, colima 0.6.7, docker 24.0.7, and the localstack image. Still throws Creating Docker SDK client failed: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).

stowns avatar Jan 04 '24 21:01 stowns