I want to see logs of container with timestamps but timezone of the logs are not set from ENV
version: '3.8'
services:
api:
build: .
ports:
- "3000:3000"
environment:
- TZ=Asia/Tehran
But after building the container usingdocker-compose up -build
and running the command below to see logs of container, I see the timestamp is not set properly for Asia/Tehran
:
docker-compose logs -ft api
2
Answers
The base image that you used is important. Here’s a quick out-of-the-box example:
You can change the TZ to different timezone to see different log date time. If you include "-t" in the logs command, you will see the host date/time prepend to your log message.
I don’t believe this is possible. The output of the timestamp in the logs when you run
docker logs -t
ordocker-compose logs -t
comes from the docker client which is forwarding the logs from the docker engine. Looking at the code for including the timestamp:The
msg.Timestamp
field is not passed throughtime.Local()
so it should always be treated as UTC, no matter the timezone of the host running the docker engine, or the client calling the docker API.The timezone of the container doesn’t apply here unless you add the timestamp to your logs of your application itself and skip passing the
-t
option.