Docker Community Forums

Share and learn in the Docker community.

Docker-py API for mac

Can someone please suggest a tutorial on docker-py to remotely access docker from python api.
Any help is appreciated.
Thanks in advance.

The documentation is here and seems quite thorough.

Read the source code and also the Docker Compose source code if you still need to see more examples of how it is intended to be used.

I think you can just contact local Docker UNIX socket without TLS if you are using Docker for Mac. They create a local socket listener to forward requests to the remote VM daemon. (something like c = Client(base_url='unix:///var/run/docker.sock')

I am following that documentation.

I have downloaded the toolbox and not just docker for mac. And i initially used c = Client(base_url=‘unix:///var/run/docker.sock’) for listening but somehow it returns an error.
I also tried to use this : client = docker.from_env(assert_hostname=True). But i think it doesn’t allow me to download images from the repository like ubuntu or busy bee.


That won’t work with Toolbox since Toolbox uses the Docker client environment variables, it does not create a local socket listener.

Those environment variables are set in wherever you are invoking the process which uses docker-py? i.e., DOCKER_HOST, DOCKER_TLS_VERIFY, and DOCKER_CERT_PATH are all set to the correct values (by docker-machine env or otherwise)?

Sorry for describing the scenario in bits and pieces. Initially I had downloaded Docker for Mac and not the entire toolbox( as it is heavier). The following command was used on docker for mac and it didn’t let me download images as mentioned earlier. But now after a bit of reading I saw the toolbox was a much better option. So here are a few questions:

  1. Which one is better : the mac for docker or the entire toolbox ?

Also for the parameters you have asked me to check I would check them after class and see if they let me do the job.

Thanks for the reply.

Hi Nathan,

export DOCKER_HOST=“tcp://"
export DOCKER_CERT_PATH=”/Users/anvika/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME=“default”

These are the configurations.

Hi nathan,

Could you please suggest something about this issue. Its quite annoying that after spending so much time I am not able to get it correct. The documentation looks straightforward but it doesn’t work when you implement it. Please help me or suggest someone i can reach out for.

requests.exceptions.ConnectionError: (‘Connection aborted.’, BadStatusLine(’\x15\x03\x01\x00\x02\x02\n’,))

This is the error i always get whenever i try to write the commands in python and access docker remotely using the following.

from docker import Client

cli = Client(base_url = ‘tcp://’)

Thanks .

Hi Anvika,

I am hitting the same issue. Were you able to fix it?


@anvika1 @bpandey You need to ensure that the TLS settings are being properly established for the Python library to connect. That looks an awful lot like TLS gone wrong. Otherwise it’s likely to try and dial in plaintext.