2

Good day!

I have difficulties on connecting to docker engine api using Python with official library docker from docker container.

Always works fine in my machine, but when I build image and started with docker-compose handled error, that python can't connect to docker host.

What I tried to do?

  1. Launch to container and run command

    import docker
    client = docker.DockerClient(base_url="tcp://127.0.0.1:2375")
    client = docker.from_env()

Get

docker.errors.DockerException: Error while fetching server API version: HTTPConnectionPool(host='127.0.0.1', port=2375): Max retries exceeded with url: /version (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91bd81d6a0>: Failed to establish a new connection: [Errno 111] Connection refused'))

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

Please, hint me how to configure container, so I can connect to local docker engine using python docker library.

Zethuman
  • 59
  • 2

1 Answers1

0

Just mount docker.sock to containers docker.sock

volumes:

  • /var/run/docker.sock:/var/run/docker.sock
Zethuman
  • 59
  • 2