Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set timezone of 'docker logs -t'?

Tags:

linux

docker

My local timezone and docker container's timezone are all set to 'GMT+8:00'. But the 'docker logs -t' still shows timestamp of 'GMT+0:00'.

the picture below is a part of output of 'docker logs -t'. The left timestamp is printed by docker, and the right timestamp is printed by application in container. enter image description here

like image 760
Z fp Avatar asked Apr 02 '19 03:04

Z fp


People also ask

What is the location of Docker logs?

By default, Docker stores log files in a dedicated directory on the host using the json-file log driver. The log file directory is /var/lib/docker/containers/<container_id> on the host where the container is running.

What is my Docker timezone?

Docker containers don't inherit the host's timezone, so you can run into unexpected scheduling issues that wreak havoc with your application. The container is using the UTC timezone, creating a one hour difference between the two times.

How do I change the date and time in a Docker container?

"If you are asking how to set the host OS's clock from inside a container, you would need to relax security on your container by adding the --cap-add SYS_TIME flag to your container at startup.


1 Answers

After some research, I found out that the docker logs -t command prints out timestamps in UTC and there is no config to change that. However, you could use a little script referenced in https://github.com/docker/cli/issues/604, where you could just pipe the output and change the given timestamp.

like image 107
Michael Altenburger Avatar answered Oct 08 '22 05:10

Michael Altenburger