markzz markzz - 24 days ago 8
Python Question

docker-py: Connection reset by peer

I am attempting to create a docker image via docker-py and I am using the following code:

import docker
import os

docker_client = docker.from_env()
path = os.path.dirname(os.path.abspath(__file__)) + "/container", tag='container-tag')

The last line throws this error:

requests.exceptions.ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer'))

The user I'm using is a member of the
group and I have checked the permissions of the socket file.

Answer Source

Since docker_client.containers.list() works for you, your issue is not with docker connection. It is that the build is failing for some reason.

Run journalctl -f -n10 in another terminal and then run your code and see if you can find what is going wrong. That will give your clear exception happening when you call, tag='container-tag')