504 Gateway Timeout after upgrading Drupal source in Docker container

Hi,

I have a couple of Docker containers running Apache and Drupal 8 and a separate container running MariaDB. These run on Ubuntu VMs in the Azure cloud. Our developers make changes to the source and it is pushed to Bitbucket. We then upgrade the Apache/Drupal containers using Rancher. This causes them to restart and perform a git clone of the newly-commit source. After this upgrade is complete, we receive a 504 Gateway Timeout for 1 to 2 minutes until the site loads properly. We have also found that it seems necessary to log into the Drupal Admin page and Clear Cache. These two issues will not work in a production environment since they will cause a customer outage. 

Is there a way to prevent this timeout from occurring or is there a work around possible? And how can we avoid clearing the cache? Please do not reply with an answer that suggest we increase the timeout value in php.ini. This is not acceptable. The page needs to load in the normal amount of time which is only a few seconds.

Thanks for any help or insight that you can provide.

Rob

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/22/feed