How to print local datetime in Docker logs

Viewed 96

I want to print the localdatetim in my Docker logs. I tried the code below, but I always get time in UTC. Lets notice that I'm actually in Rome.

Does anyone knows how to do this?

build:
stage: build
script:
 - docker info
 - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
 - echo "Project_data = \""$CI_IMAGE_COMMIT_TAG"\"" > version.py
 - docker build --pull --tag $CI_IMAGE_COMMIT_TAG .
 - export current_date=$(TZ=Europe/Rome date)
 - echo $current_date
 - docker push $CI_IMAGE_COMMIT_TAG
tags:
 - docker-socket
 - build
1 Answers

You can use TZ environment variable: With docker file

ENV TZ=Europe/Rome

With docker compose:

environment:
   - TZ=Europe/Rome
Related