DEV Community

Cover image for 🚰 Docker connection reset during builds
Justin
Justin

Posted on

🚰 Docker connection reset during builds

Recently while trying to deploy a test docker container on my homelab's docker instance, I kept running into an error similar to this one

Caused by: java.net.SocketException: Connection reset
 at java.net.SocketInputStream.read(SocketInputStream.java:210)
 at java.net.SocketInputStream.read(SocketInputStream.java:141)
 at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
Enter fullscreen mode Exit fullscreen mode

After a bunch of digging, I ran into this medium article; https://medium.com/swlh/fix-a-random-network-connection-reset-issue-in-docker-kubernetes-5c57a11de170

It summarized it's findings pretty well and walked through the whole discovery process. Something I appreciate.

Ultimately for it, it boiled down to running these commands to backup, flush, and reset iptables

# Keep a backup of the current rules incase we have to go back
iptables-save > /root/firewall.rules

# Flush all the current rules
iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

# Confirm the rules are now empty
iptables -L
Enter fullscreen mode Exit fullscreen mode

Then I had to restart docker with service docker restart for docker to reset it's own iptable rules. But from then on, no more connection reset issues.

In the event you need to roll back, you can use

iptables-resoter < /root/firewall.rules
Enter fullscreen mode Exit fullscreen mode

Now get back to building something awesome!

Top comments (0)