4

I want to install docker hosts on a server running CentOS7(that's running in Virtualbox on my PC if it matters).

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.

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

$ 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?

matanc1
  • 6,525
  • 6
  • 37
  • 57
  • If your server is CentOS, you can run docker containers directly on top of it without using docker-machine. Docker-machine is mostly for Windows/OS X users to create a Linux virtual machine (and then run docker containers inside the virtual machine). – Xiongbing Jin Mar 19 '16 at 16:08
  • I know, however I'm experimenting with deploying containers on a linux machine (from a windows PC). AFAIK, using docker-machine to provision the hosts is the right way to go (rather than SSHing to the virtual machine and managing the hosts there). – matanc1 Mar 19 '16 at 16:10
  • Sorry I don't understand "deploying containers on a linux virtual machine". What exactly do you need to achieve? – Xiongbing Jin Mar 19 '16 at 16:13
  • I corrected the previous comment to "linux machine" instead of "linux VM". I've got two goals: 1. Learn how to use docker. 2. Ultimately I want to deploy an app but on a private server where I work (not a cloud provider). – matanc1 Mar 19 '16 at 16:17
  • Try `docker-machine -D` to see more detailed debugging information. – Xiongbing Jin Mar 19 '16 at 16:34
  • For my understanding, `docker-machine` creates a new vm. For example, if you use the Amazon EC2 driver, it creates a new instance on Amazon EC2. For your use case, you are creating a new vm **inside** the CentOS machine, and then you are going to deploy your app **inside that vm**. This is totally unnecessary IMO, unless you have particular reason to do so. – Xiongbing Jin Mar 19 '16 at 16:40
  • I meant to say **inside a container inside that vm which is again inside your CentOS machine** for the second bold text. – Xiongbing Jin Mar 19 '16 at 16:47
  • I think it creates a new VM only if you use a driver from one of the cloud providers (as that's what you'd expect). From the docs: "Docker Machine is a tool for provisioning and managing your Dockerized hosts (hosts with Docker Engine on them). Typically, you install Docker Machine on your local system .... You can use Machine to install Docker Engine on one or more virtual systems. These virtual systems can be local or remote". I'm trying to use it to provision the docker engine on a CentOS server from a windows PC. – matanc1 Mar 19 '16 at 16:54

1 Answers1

7

Yes you can use docker-machine to provision and control docker-engine on a linux server, i.e. import an existing linux server as a Docker Machine. There are several requirements for this:

  1. Only a few OS are supported, see https://docs.docker.com/machine/drivers/os-base/. Support for CentOS is experimental at the moment
  2. Your SSH key need to be either without password, or managed by 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)

Once the requirements are satisfied, you can import your server as a Docker Machine using one of the methods below

  1. If your SSH key has no password

    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

    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. 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.

Community
  • 1
  • 1
Xiongbing Jin
  • 11,779
  • 3
  • 47
  • 41