这是我的userdata.yml:
#cloud-config
users:
- default
- name: ubuntu
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh-authorized-keys:
- ssh-rsa XXXXXXXXXXXXXX
使用docker-machine命令创建虚拟机:
docker-machine --debug create --driver openstack
--openstack-auth-url http://x.x.x.x:5001/v3
--openstack-domain-id defaule
--openstack-endpoint-type adminURL
--openstack-floatingip-pool ext-net
--openstack-keypair-name mykey
--openstack-flavor-id 4
--openstack-image-name ubuntu-16.04-cloud
--openstack-net-name private
--openstack-password XXXXX
--openstack-private-key-file /home/demo/id_rsa
--openstack-sec-groups default
--openstack-ssh-user ubuntu
--openstack-tenant-name admin
--openstack-user-data-file /home/demo/userdata.yml
--openstack-username admin
vm
创建vm之后,docker-machine卡住“等待ssh可用”。
这是调试输出:
Getting to WaitForSSH function...
(vm) Calling .GetSSHHostname
(vm) Calling .GetSSHPort
(vm) Calling .GetSSHKeyPath
(vm) Calling .GetSSHKeyPath
(vm) Calling .GetSSHUsername
Using SSH client type: external
Using SSH private key: /root/.docker/machine/machines/vm/id_rsa (-rw-------)
&{[-F /dev/null -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none ubuntu@10.50.2.36 -o IdentitiesOnly=yes -i /root/.docker/machine/machines/vm/id_rsa -p 22] /usr/bin/ssh <nil>}
About to run SSH command:
exit 0
SSH cmd err, output: exit status 255:
Error getting ssh command 'exit 0' : ssh command error:
command : exit 0
err : exit status 255
output :
我尝试通过命令ssh到vm:
ssh -i /root/.docker/machine/machines/vm/id_rsa ubuntu@10.50.2.36
但是收到错误消息:
Permission denied (publickey).
所以,我尝试另一个密钥,该密钥位于--openstack-private-key-file / home / demo / id_rsa
的选项中。 ssh -i /home/demo/id_rsa ubuntu@10.50.2.36
ssh成功!
我检查了两个键, /root/.docker/machine/machines/vm/id_rsa 和 / home / demo / id_rsa 但是两个键是相同的。
我很困惑,为什么同样的键,一个可以ssh,另一个不能ssh?
答案 0 :(得分:0)
为了让Docker-Machine在OpenStack上设置虚拟机,您需要激活config_drive选项:docker-machine --openstack-config-drive [OTHER_OPTIONS] <MACHINE_NAME>