This is a Vagrantfile for running an Ubuntu VM with Docker installed, exposing the Docker HTTP API over TCP port 2375
to the Host-only Network, which allows you to use Docker on your non-Linux workstation.
Unlike boot2docker, this is a full-fledged Ubuntu VM, rather than being based on TinyCore Linux. As such, VirtualBox Guest Additions are installed, so shared folders and other features work as expected.
If supports Docker volume mounts from your host (OSX) filesystem into the Docker container. To facilitate this support, it shares your entire $HOME
into the VM at the exact same path. This ensures the absolute host path you must specify to docker run -v #{host_path}:#{container_path}
is resolved to the same place in the VM as it exists in your home directory. This is also convienient because in most every case, your user directory is the only shared folder you'll need to set up. This makes for less hassle, which is the whole point of this workflow.
bash <(curl -fsSL https://raw.githubusercontent.com/rtlong/docker-vagrant/master/install.sh)
Clone the repo somewhere for safe keeping (~/.local/opt/docker-vagrant
might make a good spot) and then install the file bin/docker-vagrant
to your $PATH
somewhere using a symlink.
prefix=$HOME/.local
mkdir -p $prefix/opt $prefix/bin
echo $PATH | grep -o $prefix/bin
# if that returned nothing, add $prefix/bin to your PATH in your shell config (or choose a different prefix directory)
git clone 'https://github.com/rtlong/docker-vagrant.git' $prefix/opt/docker-vagrant
ln -s $prefix/opt/docker-vagrant/bin/docker-vagrant $prefix/bin/docker-vagrant
Now, without ever having to cd
to the clone directory, you can work with this VM using the command docker-vagrant
:
docker-vagrant up
Note: the shared folder is configured to use NFS, which should be supported on OSX just fine, but I haven't tested on Linux or Windows. Vagrant's going to use
sudo
while bringing the VM up, in order to alter your system's NFS exports file. Please see the Vagrant NFS documentation for more info about this as well as how to avoid typing your password upon eachdocker-vagrant up
.
After Vagrant brings up the new VM, it will print some intructions which you'll need to follow:
- Required:
- Set the
DOCKER_HOST
environment variable; feel free to put this in your shell RC file for ease, or just export it when needed.
- Set the
- Optional, but highly recommended one-time step:
- Define a
docker.dev
host in/etc/hosts
pointing to the host-only-networking IP address of the VM
- Define a
Vagrant tends to automatically Pause VMs when you sleep your Mac, so if you see timeouts while attempting to talk to Docker, simply try a docker-vagrant up
to resume the VM.
To alter the IP address or RAM/CPU allocation, copy config.rb.example
to config.rb
and change settings accordingly.
-
- Although, there is nothing in the Vagrantfile that is VirtualBox-specific, and the base image supports VMWare Fusion, so that may also work, but it's not tested.
-
-
OSX: You can install via Homebrew Cask:
brew cask install vagrant
-
-
Docker client
-
OSX: I recommend using Homebrew to install just the docker client.
brew install docker
(The offical Docker installation instructions for OSX tell you to use the boot2docker installer. The
docker
client this installs will work perfectly fine, though be aware that this package installs thedocker
CLI client as well as the boot2docker VM andboot2docker
management CLI tool. As mentioned in the description, this project is distinct from boot2docker and doesn't require it. It doesn't necessarily hurt to have boot2docker installed, although be aware that there may be conflicting assumptions made by this project and boot2docker -- one that comes to mind is that it uses TLS by having you set theDOCKER_TLS_VERIFY
variable in your shell, which will cause issues for this project.) -
Other OS: see the official Docker instructions
-
Contributions, thoughts, and criticisms are welcome.