Docker Machine Regenerate Certs Not Working
If you are having issues with docker-machine not being able to connect to a local machine, getting the following error:
$ docker-machine env dev Error checking TLS connection: Host is not running
Or:
docker-machine env dev Error checking TLS connection: Error checking and/or regenerating the certs: There >was an error validating certificates for host "192.168.99.100: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 running >containers.
There are different options to get around it, but the only that worked for me was to create a new machine, and use those certs in the old machine.
Something like the following script might work:
#!/bin/bash
cd ~/.docker || exit
cp -R machine machine.bak
rm -rf machine
docker-machine create deleteme
docker-machine rm -rf deleteme
cd machine/machines || exit
for m in $(ls ~/.docker/machine.bak/machines)
do
cp -R "../../machine.bak/machines/$m" .
rm "$m/cert.pem"
rm "$m/key.pem"
cp ../certs/cert.pem "$m"
cp ../certs/key.pem "$m"
done
for m in $(ls ~/.docker/machine.bak/machines)
do
docker-machine regenerate-certs -f
done
Be advised that you might not want to regenerate certs in all of your machines. Like all code for the internet, be careful in how you use it.