Thiago
Thiago

Reputation: 263

Change date in docker container

When i create a new Date() in my back-end the date is in UTC±00:00 format.

I need the UTC-3 format. I tried some things like this or this, but no working.

Wen i type docker exec -it 68856c74974a date i have :

Mon Jun 22 17:15:22 UTC 2020

And i need :

Mon 22 Jun 14:15:22 -03

$ docker image ls
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ubuntu                  latest              74435f89ab78        5 days ago          73.9MB
playcode-runner_front   latest              e53bf65cc234        2 weeks ago         1.44GB
playcode-runner_api     latest              be1e67561898        2 weeks ago         186MB
phpmyadmin/phpmyadmin   latest              6f9550cff175        3 weeks ago         469MB
hello-world             latest              bf756fb1ae65        5 months ago        13.3kB
node                    10.14.2             8a752d5af4ce        18 months ago       894MB
mysql                   8.0.3               00400babc1b7        2 years ago         343MB
anapsix/alpine-java     jdk8                ed55c27d366d        3 years ago         171MB

And:

$ docker image inspect playcode-runner_api

Only a part:

"Architecture": "amd64",
"Os": "linux",
"Size": 185505062,
"VirtualSize": 185505062,

Upvotes: 1

Views: 2575

Answers (2)

BMitch
BMitch

Reputation: 264761

Setting the TZ variable works for me:

$ docker run -it --rm -e TZ=UTC ubuntu date -R
Thu, 25 Jun 2020 14:17:30 +0000

$ docker run -it --rm -e TZ=UTC-3 ubuntu date -R
Thu, 25 Jun 2020 17:17:32 +0300

With docker exec, it gets the environment from when you start the container, so you'll need to recreate the container with the desired environment:

$ docker run -d --rm -e TZ=UTC --name utc ubuntu tail -f /dev/null
8abcb471c2fb7c933bbdabd629e0d1d08cd926017ee5f7ccf7d54337d1fd4460

$ docker run -d --rm -e TZ=UTC-3 --name utc-3 ubuntu tail -f /dev/null
670336f127097a1c9f488a086dfd40496be433a7434dd9a3ac38feaaaabbb5db

$ docker exec utc date -R
Fri, 26 Jun 2020 00:08:52 +0000

$ docker exec utc-3 date -R
Fri, 26 Jun 2020 03:08:59 +0300

Upvotes: 3

VonC
VonC

Reputation: 1327736

One possibility would be to make your own Dockerfile, FROM the image you are currently using, and add (as in here):

USER theRightUser
RUN echo "alias date='date -Is'>>~/.bashrc"

That would then use ISO-8601 for displaying the date like:

2020-06-24T22:04:10+02:00

Upvotes: 1

Related Questions