简体   繁体   English

如何在私人服务器上使用docker-machine?

[英]How to use docker-machine on a private server?

I want to install docker hosts on a server running CentOS7(that's running in Virtualbox on my PC if it matters). 我想在运行CentOS7的服务器上安装docker主机(如果重要的话,它在我的PC上的Virtualbox中运行)。

I'm aware that there are drivers for multiple cloud providers (Amazon, Google, DigitalOcean etc) but I can't figure out what to do if I want to use my own private server. 我知道有多个云提供商(亚马逊,谷歌,DigitalOcean等)的驱动程序,但如果我想使用自己的私人服务器,我无法弄清楚该做什么。

I've tried using --driver generic with the guest OS's IP, and an SSH key I created and copied using ssh-keygen and ssh-copy-id but I got 我尝试使用--driver generic与guest OS的IP,以及我使用ssh-keygenssh-copy-id创建和复制的SSH密钥但我得到了

$ docker-machine create -d generic --generic-ip-address=<IP> --generic-ssh-key ~/.ss
h/id_rsa --generic-ssh-user <user> centos

Running pre-create checks...
Creating machine...
(centos) Importing SSH key...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with centos...
Error creating machine: Error running provisioning: exit status 1

What am I doing wrong? 我究竟做错了什么?

Can it have something to do with the fact that I installed CentOS in Virtualbox? 这与我在Virtualbox中安装CentOS的事实有关吗?

Yes you can use docker-machine to provision and control docker-engine on a linux server, ie import an existing linux server as a Docker Machine . 是的,您可以使用docker-machine在Linux服务器上配置和控制docker-engine ,即将现有的Linux服务器作为Docker Machine导入。 There are several requirements for this: 这有几个要求:

  1. Only a few OS are supported, see https://docs.docker.com/machine/drivers/os-base/ . 仅支持少数操作系统,请参阅https://docs.docker.com/machine/drivers/os-base/ Support for CentOS is experimental at the moment 目前对CentOS的支持是实验性的
  2. Your SSH key need to be either without password, or managed by ssh-agent . 您的SSH密钥需要没有密码,或者由ssh-agent管理。
  3. Your user account on the server need to be able to run sudo without password (see this link https://stackoverflow.com/a/24648413/4190526 on how to do it) 您的服务器上的用户帐户需要能够在没有密码的情况下运行sudo(请参阅此链接https://stackoverflow.com/a/24648413/4190526了解如何操作)

Once the requirements are satisfied, you can import your server as a Docker Machine using one of the methods below 满足要求后,您可以使用以下方法之一将服务器导入Docker Machine

  1. If your SSH key has no password 如果您的SSH密钥没有密码

     docker-machine create -d generic --generic-ip-address server-ip --generic-ssh-key key-file --generic-ssh-user username machine-name 
  2. If you use ssh-agent to manage your key 如果您使用ssh-agent来管理密钥

     docker-machine create -d generic --generic-ip-address server-ip --generic-ssh-user username machine-name 

Then you'll be able to use docker-machine commands on your local machine to control this remote server. 然后,您将能够在本地计算机上使用docker-machine命令来控制此远程服务器。 This means that you can start, stop, kill, restart the server, so use it with extreme caution 这意味着您可以启动,停止,终止,重启服务器,因此请谨慎使用

Also, in general, due to the requirements listed at the beginning, and the fact that you'll be able to stop or kill the server, I would NOT recommend doing this. 此外,一般来说,由于开头列出的要求,以及您将能够停止或终止服务器的事实,我不建议这样做。 It is much safer to SSH into your server and do everything from there. SSH进入您的服务器并从那里做一切都更安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM