I'm doing a lot of deploying and tearing down of VMs locally and on several cloud services (on the order of two or three a day) and my biggest problem with this is that apt-get install often fails with a 503 error, or it chooses a mirror that is very slow and downloads will fail or exceed a ten minute timeout. This happens at least once a week, sometimes every day. This is on a highly reliable, fast network locally as well as on cloud services like google cloud, aws, etc.
Right now all I'm running is
apt-get update
apt-get install xyz
For various common packages like mongo, java, nodejs, git, etc.
How can I make apt-get more robust in startup scripts that build these VMs?