Resolve Docker time drift between container and host machine

I’ve had a number of projects now that use Let’s Encrypt and AWS services which are time sensitive for generating things like SSL certificates or for generating signed CloudFront one time access URLs.

However, over time these services are affected by a time drift between the Docker container and the host machine and results in expired SSL certificates or signed URLs resolving with Access Denied or Authorization Failed.

In order to sync your host time to your Docker container you can simply map timezone and localtime as volumes within the container.

volumes:
    - /etc/timezone:/etc/timezone
    - /etc/localtime:/etc/localtime