eclipse-mosquitto/mosquitto

how to set timezone on docker image

Closed this issue · 4 comments

jipp commented

I have the problem that I canot set the timezone on the docker image.

configuring the timestamp like this:
log_timestamp_format %m/%d/%y %H:%M:%S

give me an ofset from the UTC time to the CET (where I life)

tools needed to set the env seems not part of the docker image

If your container is called mosquitto, then run the command below to install the tzdata package, which will then let you set the timezone:

docker exec mosquitto apk add tzdata
jipp commented

Hi

tested it with docker-compose. so works and shows the correct timezone.

thx for the hint

I have the same problem, my compose file (portainer) is:

services:
mosquitto:
image: eclipse-mosquitto
container_name: mosquitto
network_mode: host
restart: always
volumes:
- /volume1/docker/mosquitto/log/:/mosquitto/log
- /volume1/docker/mosquitto/data/:/mosquitto/data
- /volume1/docker/mosquitto/config/:/mosquitto/config
environment:
- TZ=Europe/Amsterdam

Do you have any idea ?

thank you for helping a newbee.

jipp commented

actually it is a little tricky/indirect.

You need to have a separate Dockerfile to add the tzdata to the official eclipse-mosquitto image. This one will build a new image including the missing package:

cat Dockerfile 
ARG version=latest

FROM eclipse-mosquitto:$version

WORKDIR /

RUN apk add --no-cache tzdata && \
    rm -rf /var/cache/apk/*

To get it now working you cannot use the default image inside the docker-compose yml file anymore. You have to add the reference/build instruction to it and also save the Dockerfile above to the directory where the .yml file is located:

services:
mosquitto:
#image: eclipse-mosquitto
build: .
container_name: mosquitto
network_mode: host
restart: always
volumes:
- /volume1/docker/mosquitto/log/:/mosquitto/log
- /volume1/docker/mosquitto/data/:/mosquitto/data
- /volume1/docker/mosquitto/config/:/mosquitto/config
environment:
- TZ=Europe/Amsterdam