Wednesday, 20 January 2021

Docker container time drift using WSL2

I recently came across an issue that my Ubuntu Docker containers were failing restoring packages and this was due to them having a different time than my Windows 10 laptop.

After Googling the solution suggested was to reboot my laptop but as I'd just turned it on and got everything setup this wasn't something that I wanted to do.

The commands that most people suggested was to run a command in the container to re-synchronise the time with the host but the command returned an error when I tried this.

Eventually I found a github issue which implied it was a bug with Windows Subsystem for Linux.

Thankfully to re-synchronise the time it was quite simple, just run this command from a PowerShell window:

wsl --shutdown

Docker Desktop will quickly inform you that it isn't working and suggest you start it.

Once it is started again everything was back in sync and I could restore packages again!