Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create ubuntu based docker host by using docker-machine with VirtualBox?

I'm new to a docker and tried to create docker host with docker-machine.

Currently, I use VirutalBox for trial environment.

When I created docker host with docker-mahine, it created VM with Boot2Docker on VirtualBox by default. But I want to create a docker host with Ubuntu 15.10 on Virtualbox.

Is it possible to use docker-machine for creating Ubuntu based docker host on VirtualBox?

like image 810
takanabe Avatar asked Nov 26 '15 10:11

takanabe


2 Answers

Is it possible to use docker-machine for creating Ubuntu based docker host on VirtualBox?

Yes, but not with docker-machine directly, which relies on a TinyCore-based linux distribution of 30 Mo only.

You can try and launch a full-fledge Ubuntu VM, and in it follows the regular docker installation for Ubuntu.

like image 20
VonC Avatar answered Nov 14 '22 03:11

VonC


OP didn't describe how they used the generic driver to solve their problem, so here's how I did it in case anyone's interested:

  1. Get Ubuntu Server ISO
  2. Create a machine in VirtualBox. I called mine "Ubuntu template" because I want to learn Swarm locally, so I want a machine that I'll be able to duplicate and get subsequent machines quickly after the longer initial setup.
  3. Enable bridged networking instead of NAT for the machine in the settings
  4. Start the machine and install Ubuntu using the ISO. During installation it'll give you an option to install OpenSSH, select that option. It'll also ask you to create a new user. I called mine "ubuntu" with password "ubuntu". You'll use this user a few times, so set the credentials to something easy to remember
  5. After installation, switch to root: sudo su
  6. Change root's password to something easy to remember using passwd
  7. Generate keys: ssh-keygen
  8. Make the keys you just generated authorized: cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
  9. Edit the file /etc/ssh/sshd_config and change the line with "PermitRootLogin" so it reads PermitRootLogin yes
  10. Restart SSH to activate the changes: service ssh restart
  11. Run ifconfig and take note of the machine's IP
  12. Open terminal on your host computer
  13. Run (with your machine's IP substituted):
    ssh [email protected] 'cat ~/.ssh/id_rsa' > ~/.ssh/docker_test
  14. Run:
    ssh [email protected] 'cat ~/.ssh/id_rsa.pub' > ~/.ssh/docker_test.pub
  15. Run (back in the VM) shutdown now
  16. In VirtualBox, clone the template machine (check the checkbox to reinitialize MAC address). I named mine ubuntu-1
  17. Start the new virtual machine and run echo 'ubuntu-1' > /etc/hostname and then reboot. That's only necessary if you're going to create more machines from the same template, then you'd name them ubuntu-1, ubuntu-2 and so on
  18. Run ifconfig to find out the IP of the cloned machine
  19. On your host machine run:
    docker-machine create --driver generic --generic-ip-address 10.10.10.90 --generic-ssh-key ~/.ssh/docker_test ubuntu-1

It might take a few minutes to complete (mostly on the "Installing docker" step) but you should then have a working Ubuntu-based docker machine. You can verify that it works by running docker-machine use ubuntu-1 and then docker run hello-world

It's more involved than using Boot2Docker, but after the initial setup it should be quite workable. I haven't done too much with it yet, I just verified that it seems to work by running hello-world, so there might be more gotchas down the road like there often are with Docker.

Extra tip: VirtualBox allows you to run machines in headless mode. After the initial setup and allowing root access via SSH it'll probably be more convenient to run the machines headless and connect to them via SSH if necessary and you can close VB's GUI and the machines are now running like services in the background.

like image 184
Rafał G. Avatar answered Nov 14 '22 01:11

Rafał G.