Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Start Docker in VM with a simple command

Start a VM with Docker with a simple command

This is how to easily setup a VM with Docker and Docker Remote API enabled.
We use VirtualBox, Vagrant and Docker for that.

First install VirtualBox
and Vagrant

Run vagrant version to check that vagrant is correctly installed.

Save the Vagrantfile from this gist to a local directory.
Go inside the directory and run vagrant up. The first startup will take a few minutes to download everything.
Then you have a ready to use Virtual Machine with Docker.

Stop VM

To STOP, but not delete the VM run vagrant suspend.
To DELETE the VM run vagrant destroy.

Restart VM

Restart the VM with vagrant up

Login to VM with a terminal

Run vagrant ssh to login to your VM.
On Windows you might have to put ssh.exe to your %PATH%. If you have installed git, you can use C:\Program Files\Git\usr\bin
You can also login via Putty on host: "localhost", Port "2222", login: "vagrant", password: "vagrant".

Vagrant.configure(2) do |config|
#The Virtual Machine runs with Ubuntu 14.04 (Trusty Tahr) 64 Bit = "ubuntu/trusty64"
#Wait max 10 minutes (600 seconds) to start VM without provisioning
config.vm.boot_timeout = 600
#use DHCP to get IP address "private_network", type: "dhcp"
# use this, instead of DHCP (see above), to set a static ip "private_network", ip: ""
#1GB RAM for VM
config.vm.provider :virtualbox do |p|
p.customize ["modifyvm", :id, "--memory", 1024]
#Show ip address
config.vm.provision "shell", inline: "ifconfig"
#stop running docker containers
config.vm.provision "shell", inline: "sh -c 'docker stop $(docker ps -aq) && docker rm $(docker ps -aq); true'"
#Install Docker
config.vm.provision "docker" do |d|
#expose docker remote api
config.vm.provision "shell", inline: "chmod 666 /var/run/docker.sock"
config.vm.provision "shell", inline: "docker run -p 2375:2375 -d -v /var/run/docker.sock:/var/run/docker.sock:ro jarkt/docker-remote-api"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.