docker-py: Connection reset by peer

2.7k views Asked by At

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"
docker_client.images.build(path=path, 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 docker group and I have checked the permissions of the socket file.

1

There are 1 answers

0
Tarun Lalwani On BEST ANSWER

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

docker_client.images.build(path=path, tag='container-tag')