2

I have a CentOs host running a docker Debian container.

The container has the wrong localtime and timezone: how can I synchronize it with the host date?

I'm trying with mounting volumes on the docker-compose with /etc/localtime but it doesn't work.

The solution I prefer should be one of them:

  • set a particular ENV in the Dockerfile
  • mount properly volumes in the docker-compose.yml
Alessandro C
  • 121
  • 1
  • 3

3 Answers3

2

You can add your local file /etc/localtime as volume in your docker-container. Update your docker-compose.yml with the following lines.

volumes:
    - "/etc/localtime:/etc/localtime:ro"

And, Then:

# docker-compose up -d

Now the container time is the same as on your host.

shgnInc
  • 1,634
  • 3
  • 21
  • 29
0

I have found the solution.

In the Dockerfile, write:

ENV TZ=<your timezone>

Example:

ENV TZ=Europe/Rome
Alessandro C
  • 121
  • 1
  • 3
0

You shoudl define has an ENV the TZ and also add change the localtime softlink and place it in the timezone file:

ENV TZ=Europe/Lisbon
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
João Alves
  • 511
  • 2
  • 6