Set timezone for Caddy 2 (official docker image)

1. Caddy version (caddy version):

Caddy v2.0.0-rc.3

2. How I run Caddy:

By using docker-compose, details below.

a. System environment:

Ubuntu 18.04
Docker version 19.03.5
docker-compose version 1.21.2

b. Command:

docker-compose up -d

c. Service/unit/compose file:

version: '3.6'

services: 
    caddy:
        image: caddy
        container_name: caddy_reverse_proxy
        command: caddy run --watch --config /etc/caddy/Caddyfile
        volumes:
            - $PWD/Caddyfile:/etc/caddy/Caddyfile
            - caddy_data:/data
            - caddy_config:/config
        ports:
            - 80:80
            - 443:443
        networks:
            - caddy
        environment: 
            TZ: Europe/Stockholm

volumes:
    caddy_data:
    caddy_config:

networks:
    caddy:
      name: caddy_network

d. My complete Caddyfile or JSON config:

Not relevant.

3. The problem I’m having:

The timezone is not set which makes the log output be two hours off. I want to have it configured, but have no clue about how to do this with the official docker-image provided.

4. Error messages and/or full log output:

N/A

5. What I already tried:

I’ve tried setting TZ=Europe/Stockholm in the docker-compose which have worked for other docker use cases but it does not seem to work for this one. Reading on Stackoverflow points me to different CLIs which not seem to be available in this image.

I figured this should be a quite common use case? But didn’t find anything when searching through the forum…

6. Links to relevant resources:

1 Like

It’s most common to leave timezones on systems as UTC and just add your current timezone’s offset in your head as you read the logs, or using tooling that ingests the logs as UTC and displays them to you in your local timezone. It avoids plenty of issues you might encounter due to wacky timezone rules.

But if you must, you’ll need to make a Dockerfile that extends from the caddy one that installs tzdata:

FROM caddy:alpine
RUN apk add --no-cache tzdata

There was some discussion about this a while back, and we decided not to add tzdata:

Also FYI, you’re using an old version of Caddy. Make sure to docker pull caddy to get the latest!

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.