Skip to content

Instantly share code, notes, and snippets.

@RyanNutt
Created February 28, 2020 14:11
Show Gist options
  • Save RyanNutt/d1e0dcf7b9adc458c2ad57c4c02275cd to your computer and use it in GitHub Desktop.
Save RyanNutt/d1e0dcf7b9adc458c2ad57c4c02275cd to your computer and use it in GitHub Desktop.
Update docker clock

Update Docker Clock

I switched to Docker from Virtual Box as a local web development environment a few months ago and find it much easier to work with. Except for one issue.

What I've found is that if a Docker container is running when my computer goes to sleep the clock stops and the container falls behind by however long my computer was asleep. Since the container is supposed to be in sync with my computer there didn't seem to be an easy way to update the container's clock. Lots of work arounds, but nothing quick and easy. And I couldn't find anything that worked without stopping the container first.

Stack Overflow to the rescue. I found this one liner that does exactly what I needed.

docker run --rm --privileged alpine hwclock -s

Ran this on the command line and it updated clocks in containers, and most importantly on already running containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment