I have dockers running on Linode servers. At times, I see that the time is not right on the dockers. Currently I have changed the run script in every docker to include the f
You can add your local files (/etc/timezone and /etc/localtime) as volume in your Docker container.
Update your docker-compose.yml
with the following lines.
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
Now the container time is the same as on your host.
If you're using docker-machine, the virtual machines can drift. To update the clock on the virtual machine without restarting run:
docker-machine ssh <machine-name|default>
sudo ntpclient -s -h pool.ntp.org
This will update the clock on the virtual machine using NTP and then all the containers launched will have the correct date.
For me, restarting Docker Desktop did not help. Shutting down Win10 and start it again, it did help.
Although this is not a general solution for every host, someone may find it useful. If you know where you are based (UK for me) then look at tianon's
answer here.
FROM alpine:3.6
RUN apk add --no-cache tzdata
ENV TZ Europe/London
This is what I added to my Dockerfile ^ and the timezone problem was fixed.
This will reset the time in the docker server:
docker run --rm --privileged alpine hwclock -s
Next time you create a container the clock should be correct.
Source: https://github.com/docker/for-mac/issues/2076#issuecomment-353749995
Add /etc/localtime:/etc/localtime:ro
to the volumes
attribute:
version: '3'
services:
a-service:
image: service-name
container_name: container-name
volumes:
- /etc/localtime:/etc/localtime:ro