49

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.

3
  • 3
    Check your system clock (or a mismatch between your system timezone & clock)
    – guiverc
    Jul 25, 2018 at 3:54
  • 1
    @guiverc yes updating the local time worked
    – Shash
    Jul 25, 2018 at 4:43
  • @Shash If it worked, then please accept the submitted answer so that people will know that it worked for you!
    – devinbost
    Mar 20, 2019 at 20:56

8 Answers 8

73

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.

3
  • 2
    This solved the problem for me too
    – Turp
    Apr 3, 2020 at 3: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. May 15, 2021 at 3:46
  • 3
    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, 2021 at 7:51
33

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)

3
  • 5
    The system clock can be off after you put a virtual machine to sleep... that's what happened to me...
    – sdittmar
    Aug 2, 2020 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, 2020 at 3:28
  • 2
    Quick command to fix clock: sudo systemctl restart systemd-timesyncd.service Aug 24, 2021 at 16:31
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.

4
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
    – David
    Feb 5, 2020 at 23:30
  • 3
    Hi @David. It is not an answer to OP, purely because OP asked this in 2018, when this bug was not present in Docker yet. Now, this bug is present, and this StackOverflow question is the first hit in Google when searching for "docker Release file is not valid yet". Therefore, the answer is useful to everyone visiting, as it is a solution for the problem posted above, even if the root cause for the original poster was something different. Feb 7, 2020 at 9:01
  • Do you prefer I open a new question and answer my own question instead? Feb 7, 2020 at 9:04
  • It should be noted that this is specific to Docker Desktop on Windows. The solution based on Ruben's answer is simply to "restart Docker Desktop". Mar 24, 2020 at 12:11
16

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
3
  • 2
    Finally, the right answer to my problem. Thanks bro
    – Sabrina
    Dec 17, 2019 at 13:28
  • It should be the accepted answer. It's the fastest and easiest way to update your system clock. Dec 21, 2019 at 22:24
  • and in fact, the only answer that worked for me. Restarting did nothing.
    – Brad
    Nov 6, 2021 at 14:00
8

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

6
  • This helped me install the update but didn't solve the issue
    – Dinesh
    Oct 12, 2020 at 3: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. ivankrizsan.se/2015/10/31/time-in-docker-containers
    – egrubbs
    Nov 9, 2020 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. github.com/justincormack/nsenter1
    – egrubbs
    Nov 9, 2020 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. github.com/wolfcw/libfaketime
    – egrubbs
    Nov 9, 2020 at 16:16
  • This helped me update my Debian sid testbed box. I had to increase the number by like 21 days though. Mar 27, 2021 at 15:46
6

This helped me to fix time in docker:

docker run --rm --privileged alpine hwclock -s
1
  • This should be the correct answer.
    – noomz
    Jan 27, 2021 at 14:01
6
sudo hwclock -s

helped fix the issue for me.

Docker 2.2.3.0 running on WSL 2 Windows 10 19603

2
  • I tried "sudo hwclock -s --verbose" and got this error "No usable clock interface found"
    – Dinesh
    Oct 12, 2020 at 3:14
  • This fixed the issue for me +1
    – Eng.Fouad
    Apr 19, 2021 at 20:22
3

On Docker Desktop:

Settings → Reset → Reset to factory

3
  • This was the only thing that worked for me. Thank you!
    – mmell
    Apr 2, 2020 at 23:56
  • Troubleshoot→ Restart did it for me
    – maeneak
    Apr 28, 2020 at 9:53
  • I am using Version 2.4 and "Reset to factory defaults" is found under Troubleshoot. But reset didn't solve the problem for me.
    – Dinesh
    Oct 12, 2020 at 3:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.