Ubuntu timedatectl fails in Docker container

I’ve got Ubuntu 16.04 LTS running in a Docker container (hosted on macOS). The date/time is off by about four days.

$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.1 LTS"
$ date
Sun May  7 05:57:21 UTC 2017

Effective date is 11 May 2017 06:17:13 UTC.

  • Docker & Rails | bundler: command not found: rails
  • Docker: How do I pull a specific build-id?
  • How to interact with docker swarm to change the strategy in scheduler
  • How can I resize disk size of a Docker container?
  • How can I access the Kubernetes service through ClusterIP
  • Unable to install docker-compose with pip, “ImportError: No module named dockerpycreds”
  • I wanted to fix this (checking this and this) but I can’t even run timedatectl:

    $ timedatectl status
    Failed to create bus connection: No such file or directory
    

    How do I fix this?

  • Switching users inside Docker image to a non-root user
  • Running a Docker Image stored in a EC2 Container Instance
  • docker info: are huge (tens-of-thousands) container counts normal?
  • Adding custom folder to Docker using sbt-native-packager in Play JPA project
  • Docker/Jupyter notebook setting Base URL
  • Docker mongo image always save the data inside /data/db directory
  • One Solution collect form web for “Ubuntu timedatectl fails in Docker container”

    Time drift is caused by the underlying host OS which, for Docker, isn’t macOS but actually the Linux VM running on macOS. It’s related to macOS sleep times (e.g. when you close the MacBook lid). Apparently it’s recently been fixed and should be available soon: https://github.com/docker/for-mac/issues/17#issuecomment-300734810

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.