Docker certificate has expired or is not yet valid

Viewed 4732

I just installed docker for the first time and when the default virtualbox or 'docker-machine'(not sure what it is called I run into this error:

This is an excerpt

Checking connection to Docker...
Error creating machine: Error checking the host: Error checking and/or regenerat
ing the certs: There was an error validating certificates for host "192.168.99.1
01:2376": x509: certificate has expired or is not yet valid
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]
'.
Be advised that this will trigger a Docker daemon restart which might stop runni
ng containers.

I tried using the docker-machine regenerate-certs [name] command and it seemed to work no errors were raised at least. Only when I attempted to run docker's hello world command this is the result I got.

docker: error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.39/c
ontainers/create: open //./pipe/docker_engine: The system cannot find the file s
pecified. In the default daemon configuration on Windows, the docker client must
 be run elevated to connect. This error may also indicate that the docker daemon
 is not running.
See 'docker run --help'.

I searched up similar errors and found a few case where creating a new virtualbox/docker-machine(still don't know what its called) solved it but the same error that appeared with the default box showed up.

Error creating machine: Error checking the host: Error checking and/or regenerat
ing the certs: There was an error validating certificates for host "192.168.99.1
01:2376": x509: certificate has expired or is not yet valid
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]

Afterwards I gave the docker-machine ls command a try in order to see if I could find something helpful. This is the output.

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DO
CKER    ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           Un
known   Unable to query docker version: Get https://192.168.99.100:2376/v1.15/ve
rsion: x509: certificate has expired or is not yet valid
first     -        virtualbox   Running   tcp://192.168.99.101:2376           Un
known   Unable to query docker version: Get https://192.168.99.101:2376/v1.15/ve
rsion: x509: certificate has expired or is not yet valid

How can I fix it?

3 Answers

Try docker-machine regenerate-certs --client-certs.

Try this:

In your command prompt run:

docker-machine ls

it will return

NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
<name>    <status> <driver>     <state>   <url>                       <swarm> <docker>  <errors>

get the <name> of the machine you want to run (if it's the first time you are running docker, then you have only one machine running and its name is default, in this example I will call it <name>)

then run:

docker-machine kill <name>
docker-machine create <name>
docker-machine env <name>

The last command will output more lines, copy the last one, in my case it was like this:

# eval $("C:\my\path\to\docker-machine.exe" env <name>)

then paste it in the command prompt without the # and run it, the problem should be fixed now.

You can check it by running docker-machine ls, if the problem is fixed, you should see no more messages under the ERROR column.

Furthermore, it is possible that the lines

docker-machine kill <name>
docker-machine create <name>

are not required if you have only one docker-machine existing and its <name> is default.

Maybe you can vi /etc/docker/daemon.json use this setting: { "insecure-registries":[ "0.0.0.0/0" ] }

then restart service: service docker restart

and try again.

Related