Search code examples
dockercrondnsgoogle-compute-engine

What is the cause of 'getaddrinfo EAI_AGAIN' error in docker container running a cronjob and how to fix?


I am getting an error running a program in my docker container, that makes requests to third party apis. The error is 'getaddrinfo EAI_AGAIN'. From my research of existing questions, it appears that this is probably due to some sort of DNS resolution error

What's the cause of the error 'getaddrinfo EAI_AGAIN'?

For more context, I am running a docker container in a google cloud compute engine vm (container optimized os). The entrypoint to the docker image is starting a cronjob that runs the program once, every day, at noon. By the time that noon rolls around the next day, looking in the logs, I see nearly all of the requests timing out with the EAI_AGAIN error, and I am not able to ssh into my compute engine vm at all (it hangs).

My prevailing theory now is that there is some sort of network change that takes place between when the container is started to when the cronjob runs, causing DNS resolution failures, but I'm not sure if this is correct and my knowledge of docker networking is limited, and also if its related to crontab or even google compute engine. If anyone has any more info please share. I am trying to figure out how I can fix this problem and either prevent these network issues or which code to run to fix them when they happen automatically.


Solution

  • This was simply a byproduct of my Google Compute Engine VM's network failing, which was due to inadequate resources (CPU or memory). Increasing the instances size from e2-micro to e2-small did the trick