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

3 Answers 3

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.

0

I have found the solution.

In the Dockerfile, write:

ENV TZ=<your timezone>

Example:

ENV TZ=Europe/Rome
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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .