64

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,061
  • 2
  • 15
  • 27

8 Answers8

82

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
  • 921
39

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
  • 33,561
30

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
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
  • 2
  • 4
7

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
  • 119,640