Changing Docker container timezones

By default, most Docker containers seem to use UTC as the timezone. This is generally sensible for servers, however some of the web applications I maintain assume that the system timezone is ‘local’, which for the UK is Europe/London (UTC or UTC + 1, depending on the time of year).

There are lots of different ways to change the timezone within containers, but if you are using Docker Compose (and you should be), you can pass in a value for the TZ environment variable in your docker-compose.yml file. For example:

mailhog:
    image: mailhog/mailhog:latest
    ports:
      - "8025:8025"
    environment:
      TZ: "Europe/London"

You will need to rebuild the containers for this to take effect, i.e. docker-compose up --build.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.