progapandist / progapanda.org

Source code for progapanda.org

Home Page:https://progapanda.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker refuses to connect sporadically

progapandist opened this issue · comments

Screenshot 2020-06-02 at 14 44 53

Hard to recreate: approx 1/5 page loads result in Docker error. Solved with a page refresh, but annoying 😠

Yes, because it's not guaranteed to be running in some specific order (and you want to have DIND running before the blog) when you have a pod with two containers. Containers are starting concurrently.

Basically, it's a well-known problem in k8s. There are even some scripts to wait for something: https://github.com/vishnubob/wait-for-it

But since you already have picked up Go, you can just implement net socket polling on your own, just try to do a network connection to docker host before running docker run command. Just use net.Dial() and retry until it's ready.

Also, I think it would be better to use Docker's SDK instead of docker run.

Thank you so much for the suggestion! It’s exactly what I was looking for and I will explore that ASAP ❤️

the net.Dial suggestion worked like a charm, thanks a lot!