58

I am trying to update a ubuntu container with a dockerfile.

RUN apt-get update -y

But I am getting the below error.

E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet (invalid for another 9h 14min 10s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease is not valid yet (invalid for another 9h 14min 16s). Updates for this repository will not be applied.
E: Release file for http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease is not valid yet (invalid for another 9h 14min 35s). Updates for this repository will not be applied.

I checked some other solutions to the same problem like adding Acquire::Check-Valid-Until=false to apt-get like below

RUN apt-get -o Acquire::Check-Valid-Until="false" update -y

The above also fails.

Shash
  • 1,001

8 Answers8

78

Restart docker (or your computer to be certain) as the system clock is mismatched.

I spent few hours trying to figure what was going and restarting fixed it instantly.

Dennis
  • 881
  • 2
    This solved the problem for me too – Turp Apr 03 '20 at 03:08
  • If you have the NTP daemon or an equivalent installed, it fixes the clock on a reboot, so that would be why it works. – Alexis Wilke May 15 '21 at 03:46
  • 4
    For Windows users having Docker with wsl backend: I also needed to reboot wsl using wsl --shutdown and then rebooting docker host. – Guido May 17 '21 at 07:51
  • Same for me with podman, had to do podman machine stop && podman machine start – froblesmartin Mar 07 '23 at 08:50
  • I am using podman, I restart podman machine stop and start and the issue resolve – Kernelv5 Mar 08 '23 at 16:16
  • I have made sure my computer is set to the correct time & time zone, as is the VM machine I am trying to update. Restarted everything to make sure. This is not the problem. – John Smith Nov 09 '23 at 08:20
38

Correct your system clock. (in comments I also suggested checking for a mismatch between clock and your timezone too)

Refer to What is the command line statement for changing the System clock? for setting system time (I suggest going to the timedatectl answer if using a 'modern' Ubuntu release), or http://manpages.ubuntu.com/manpages/xenial/man8/hwclock.8.html (if you want to set hardware clock directly; but remember to match it up with your timezone config)

guiverc
  • 30,396
  • 6
    The system clock can be off after you put a virtual machine to sleep... that's what happened to me... – sdittmar Aug 02 '20 at 14:35
  • timedatectl didn't solve the problem for me. I get the below error root@d8e0b021f7d8:/# timedatectl System has not been booted with systemd as init system (PID 1). Can't operate. Failed to create bus connection: Host is down root@d8e0b021f7d8:/# – Dinesh Oct 12 '20 at 03:28
  • 4
    Quick command to fix clock: sudo systemctl restart systemd-timesyncd.service – SurpriseDog Aug 24 '21 at 16:31
27

I've solved my issue with updating time:

sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"
sudo apt update
0x8BADF00D
  • 736
  • 7
  • 12
  • 2
    Finally, the right answer to my problem. Thanks bro – Sabrina Dec 17 '19 at 13:28
  • It should be the accepted answer. It's the fastest and easiest way to update your system clock. – Artur Nawrot Dec 21 '19 at 22:24
  • and in fact, the only answer that worked for me. Restarting did nothing. – Brad Nov 06 '21 at 14:00
  • I would like to thank and congratulate you for this being the sole correct answer I've found on Stack Exchange, for any linux problem, in a week, literally seven consecutive days, of all-day and all-night troubleshooting. Thanks! – John Smith Nov 09 '23 at 08:23
19

If you are using Docker, a bug was recently introduced in 2.2.0 that causes time drift when the host computer goes to sleep. This desynchronizes all running docker containers, resulting in errors such as this one.

See https://github.com/docker/for-win/issues/5593 for tracking the solution and workarounds.

This was asked in 2018, when this bug was not present in Docker yet. Now, this bug is present, so this bug may be the problem for people finding this post today.

10

This didn't work for me:

apt-get -o Acquire::Check-Valid-Until="false" update

but this did:

apt-get -o Acquire::Max-FutureTime=86400 update

86400 is the number of seconds in a day. If your clock is off more than that, you will need to increase it.

Warning: Quotes can cause it to treat the number as a string. The shell will normally remove one set of quotes, but -o 'Acquire::Max-FutureTime="86400"' would only have the single quotes removed by the shell, and apt-get would see the double quotes around the number.

I tried this because GetNotBefore() in acquire-item.cc returns d->NotBefore which seems to only be affected Acquire::Max-FutureTime.

https://github.com/Debian/apt/blob/master/apt-pkg/acquire-item.cc#L1758-L1775 https://github.com/Debian/apt/blob/master/apt-pkg/deb/debmetaindex.cc#L543-L555

egrubbs
  • 201
  • This helped me install the update but didn't solve the issue – Dinesh Oct 12 '20 at 03:14
  • @Dinesh, looking at your other comments, I see that you are still trying to solve the time setting inside the docker container. If your docker host is linux, you should be able just fix the time on that linux system, but when running Docker Desktop for Windows, it is running the linux docker host inside a VM. In order for your container to change the time with hwclock, you need to run the container with --cap-add=SYS_TIME. However, every minute, the docker host will reset the time.

    https://www.ivankrizsan.se/2015/10/31/time-in-docker-containers/

    – egrubbs Nov 09 '20 at 16:09
  • @Dinesh With Docker Desktop for Windows, you can gain access to the docker host by following these instructions. However, the host uses Moby Linux which is very different from most other distributions. https://github.com/justincormack/nsenter1 – egrubbs Nov 09 '20 at 16:13
  • @Dinesh If you want to adjust the time in a specific container without adjusting it for all the containers and the host, you can use libfaketime. https://github.com/wolfcw/libfaketime – egrubbs Nov 09 '20 at 16:16
  • This helped me update my Debian sid testbed box. I had to increase the number by like 21 days though. – Marshall Whittaker Mar 27 '21 at 15:46
  • Thanks a lot! ,this is working perfect to me! – user2761808 Jun 22 '22 at 12:20
6

This helped me to fix time in docker:

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

helped fix the issue for me.

Docker 2.2.3.0 running on WSL 2 Windows 10 19603

3

On Docker Desktop:

Settings → Reset → Reset to factory

Eliah Kagan
  • 117,780