If the create command fails (in this case because I forgot the vpc-id flag) and I remove the failed image, I can't create a new one with the same name because the keypair doesn't get deleted:
$ docker-machine rm -f demo
$ docker-machine create --driver=amazonec2 --amazonec2-vpc-id=vpc-foo demo
INFO[0000] Creating CA: /Users/dan/.docker/machine/certs/ca.pem
INFO[0001] Creating client certificate: /Users/dan/.docker/machine/certs/cert.pem
ERRO[0003] Error creating machine: There is already a keypair with the name demo. Please either remove that keypair or use a different machine name.
It seems that rm -f
should remove associated keypairs.
Related: #119.
+1
it would also/meanwhile be useful for the error message to point to how to remove such a keypair -- I get this error even when docker-machine ls
does not show any machines, and docker -h
doesn't suggest any other way of removing this keypair record.
I have run into this as well. Does anyone know where these keypairs are being created? I have looked around in the machine storage path and in my home directory and come up empty.
Ok, so now I get it. This is the "Key Pair" in EC2, not anything stored locally. I was able to remove them in the EC2 management console and now all is well.
+1 @dougborg
It would also be helpful to be able to pass --amazonec2-keypair-name=whatever to re-use existing keypairs.
:+1: just ran into this - working within a group - we have a keypair we're sharing.
+1 I ran into this today too.
:+1:
+1 as well. In my case it is telling me this even though when doing an aws describe-key-pairs
_and_ looking in the AWS console the key pair doesn't even exist. Some more verbosity in debug mode would help here as well.
+1
+:1 for --amazonec2-keypair-name
+1
+1 for --amazonec2-keypair-name
You can delete the keypair in the AWS console. "Network & Security" -> "Key Pairs" -> "Delete"
+1 for keypair-name option
--amazonec2-keypair-name
馃憤
I keep running into this issue as well. Our automated docker machine creation scripts often fail and leave behind existing key pairs and then cause even more failures which require manual intervention to fix.
This bug is not fully fixed. The unhelpful error message is still there.
It should read:
Use aws ec2 delete-key-pair --key-name {{.Host}}
to delete.
I've just seen this issue too, on 1.5.3. In my case, the console showed no key pair with the relevant name, and neither did aws ec2 describe-key-pairs
. That said, aws ec2 delete-key-pair --key-name xyz
DID work, despite them not being visible...
Creating a keypair for every new instance is an ugly kludge, and it's what's causing the underlying problem. True use of an existing key pair _without_ duplication is the real solution. When with _that_ be implemented.
Simply saying 'delete the keypair manually from aws' may be a workaround, but it is NOT a solution. How is clustering supposed to work with that? That won't scale.
@m-dunbar --amazonec2-keypair-name
is what you are looking for.
Most helpful comment
You can delete the keypair in the AWS console. "Network & Security" -> "Key Pairs" -> "Delete"