Docker refuses to connect sporadically
progapandist opened this issue · comments
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!