Docker-machine Google(GCE)驱动程序无法正常工作,无法创build实例

好吧,这是非常容易重现,令人难以置信的挫折。 将超级感激任何帮助或build议! 我使用OS X El Capitan(10.11.6)上运行的Mac版Docker。 要点是Docker似乎不能通过Docker的GCE驱动程序与Google Compute Engine(GCE)协同工作(Docker官方文档参考)。

1:通过http://console.cloud.google.com/注册一个新的免费GCP(Google Cloud)帐户。 也可以从这里下载并安装Google Cloud SDK: https : //cloud.google.com/sdk/ 。

2:创build一个新的Google云项目。

3:转到Google云端控制台中的“API Manager”,然后点击“Credentials”

4:点击“Create Credentials”并select“Service Account Key”。 select“计算引擎默认服务帐户”,确保selectJSON作为输出types,然后点击“创build”。 将输出的JSON文件移动到您的用户根目录( /Users/MYUSERNAME )。

5: export GOOGLE_APPLICATION_CREDENTIALS=/Users/MYUSERNAME/NAME_OF_CREDENTIALS_FILE.json添加到.bash_profileconfiguration中: export GOOGLE_APPLICATION_CREDENTIALS=/Users/MYUSERNAME/NAME_OF_CREDENTIALS_FILE.json 。 保存文件。

6:退出terminal,并打开一个新的,所以envvariables现在设置。

7:运行gcloud config set project PROJECT_ID (其中PROJECT_ID是刚刚在Google云端控制台中创build的项目的名称)。

8:运行gcloud auth login ,这将打开一个浏览器选项卡login到Google并授予权限。 点击“允许”。

9:现在有趣的部分,按照Docker 文档 (我添加了一个–debug标志)运行以下命令:

docker-machine --debug create --driver google --google-project PROJECT_ID vm01

('vm01'是这里虚拟机的名字,这可能是你想要的任何东西。)

在非常冗长的输出结束时,我得到以下结论,由最下面的错误信息得出结论:

 (LOTS OF OTHER OUTPUT BEFORE THIS, NOT ABLE TO COPY-PASTE EVERYTHING DUE TO STACKOVERFLOW 30000 CHAR LIMIT) (vm01) Calling .GetURL (vm01) Calling .DriverName Setting Docker configuration on the remote daemon... (vm01) Calling .GetSSHHostname (vm01) Calling .GetSSHPort (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHUsername Using SSH client type: external Using SSH private key: /Users/nathan/.docker/machine/machines/vm01/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 docker-user@104.198.166.134 -o IdentitiesOnly=yes -i /Users/nathan/.docker/machine/machines/vm01/id_rsa -p 22] /usr/bin/ssh <nil>} About to run SSH command: printf %s "[Service] ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=google MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity Environment= [Install] WantedBy=multi-user.target " | sudo tee /etc/systemd/system/docker.service SSH cmd err, output: <nil>: [Service] ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=google MountFlags=slave LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity Environment= [Install] WantedBy=multi-user.target (vm01) Calling .GetSSHHostname (vm01) Calling .GetSSHPort (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHUsername Using SSH client type: external Using SSH private key: /Users/nathan/.docker/machine/machines/vm01/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 docker-user@104.198.166.134 -o IdentitiesOnly=yes -i /Users/nathan/.docker/machine/machines/vm01/id_rsa -p 22] /usr/bin/ssh <nil>} About to run SSH command: sudo systemctl daemon-reload SSH cmd err, output: <nil>: (vm01) Calling .GetSSHHostname (vm01) Calling .GetSSHPort (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHUsername Using SSH client type: external Using SSH private key: /Users/nathan/.docker/machine/machines/vm01/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 docker-user@104.198.166.134 -o IdentitiesOnly=yes -i /Users/nathan/.docker/machine/machines/vm01/id_rsa -p 22] /usr/bin/ssh <nil>} About to run SSH command: sudo systemctl -f start docker SSH cmd err, output: <nil>: (vm01) Calling .GetSSHHostname (vm01) Calling .GetSSHPort (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHKeyPath (vm01) Calling .GetSSHUsername Using SSH client type: external Using SSH private key: /Users/nathan/.docker/machine/machines/vm01/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 docker-user@104.198.166.134 -o IdentitiesOnly=yes -i /Users/nathan/.docker/machine/machines/vm01/id_rsa -p 22] /usr/bin/ssh <nil>} About to run SSH command: netstat -tln SSH cmd err, output: <nil>: Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 10.0.3.1:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN Error creating machine: Error running provisioning: Unable to verify the Docker daemon is listening: Maximum number of retries (10) exceeded notifying bugsnag: [Error creating machine: Error running provisioning: Unable to verify the Docker daemon is listening: Maximum number of retries (10) exceeded] 

刚刚解决这个问题。 我使用了Googleregistry(Ubuntu 16.04 LTS,相对于docker-machine --driver google命令使用的默认Ubuntu 15)的更新映像,它似乎工作正常。 不知道为什么。 完整的命令是:

docker-machine --debug create --driver google --google-project PROJECT_ID --google-machine-image https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20161205 vm02