9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

docker-machine上のdockerが突如動かなくなった時の対処法

Posted at

事象

コマンドを何を打っても x509: certificate has expired or is not yet valid と言われる。env でも ls でもなんでも。

$ docker-machine ls
NAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
local   -        virtualbox   Running   tcp://192.168.99.100:2376           Unknown   Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate has expired or is not yet valid

解決法その1

VMとローカルの時刻がずれている。
ぐぐっても割とこの解決方法が出てくるのであるある事案っぽい。

sudo ntpdate ntp.nict.jp

適当にntpで時刻を合わせれば解決するときもある模様。今回は解決しなかった。

解決策その2

docker-machineと通信するときに使う証明書の期限が切れている

dockerのセットアップ時に作成された証明書は3年の有効期限っぽいので
それを過ぎると突然使えなくなる。

確認方法は以下の通り。めっちゃ有効期限切れとるやんけ!!

$ openssl x509 -in ~/.docker/machine/certs/ca.pem -noout -dates
notBefore=Nov 25 13:28:00 2015 GMT
notAfter=Nov  9 13:28:00 2018 GMT

docker-machine regenerate-certs --client-certs VM名 で証明書は更新できる。

手元の docker-machine では古すぎてhelpに --client-certs がいなかったけど、最新版にupgradeしたら居ました。

$ docker-machine regenerate-certs --client-certs local
Regenerate TLS machine certs?  Warning: this is irreversible. (y/n): y
Regenerating TLS certificates
Regenerating local certificates
CA certificate is outdated and needs to be regenerated
Creating CA: /Users/agile/.docker/machine/certs/ca.pem
Client certificate is outdated and needs to be regenerated
Creating client certificate: /Users/agile/.docker/machine/certs/cert.pem
Waiting for SSH to be available...
Detecting the provisioner...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...

更新された模様。さっき確認した証明書を再度確認。

$ openssl x509 -in ~/.docker/machine/certs/ca.pem -noout -dates
notBefore=Nov  9 15:01:00 2018 GMT
notAfter=Oct 24 15:01:00 2021 GMT

こっちもおk。ls もエラーが消えました。

$ docker-machine ls
NAME    ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
local   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.09.0  
9
9
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?