A Vagrant + Docker + CLI setup for a development box
Ever wanted to have just one Vagrant machine to work across multiple projects? Well, now you can!
git clone this repository to
$HOME/somewhere in order to create the path as following:
dev-box/cli/dev-box.py into your
$PATH. In my local setup, I created a symbolic link to the
made it available in my
$PATH. From now on I'm assuming you created a symbolic link to
$HOME/somewhere/dev-box/cli/dev-box.py, named it
devbox and made it available in your
Then, setup the Vagrant machine. It will take a time, but it shouldn't take a lot.
$ devbox setup
If everything went well (and if it didn't, please post a bug
$ devbox hook .
In this case,
. is the current working directory (CWD) (
echo $PWD); it's the current directory where the
command was called. It will basically create a link between the current directory with the Vagrant's VM
Thus, you will be able to run any command from within the Vagrant machine using the files and folders listed in
It is only possible to hook one folder at a time. The CWD will be available in Vagrant's VM
/hook path. You may hook
absolute or relative paths as well. Once the hook is done, you may run commands from within the
$ devbox console
$ devbox run [commands]
$ devbox stream [commands]
The first command opens a
/bin/zsh shell prompt at the Vagrant's
$HOME folder; the second one runs the [commands]
as it would be written directly in the shell, from
$HOME (arguments and options are proxied to the machine through
vagrant ssh -c command); the last one will stream/run commands from the
To release a hook, just run:
$ devbox unhook
For any other option, please run
Docker is available by default; you don't have to hook any folder in order to run a container — if the image is
available. If you run
$ devbox run docker [commands] you can build images or create containers as it would be
available in the host machine (well, likely, the only difference is the use of an IP address different to
127.0.0.1|0.0.0.0|localhost; in this case defaulted to
192.168.44.88 — you may change that in
dev-box/Vagrantfile or creating a
dev-box/Vagrantfile.local configuring any additional option to the Vagrant
machine, including its IP address).
Create an alias for the
docker installation inside this virtual machine:
alias docker="devbox run docker"
Now you can use the
docker command normally, as it would be called from the host machine.
Well, what about
Yes, I know,
docker-machine provides (almost) the same services and it also has a larger community to keep it really
good. But I also need to take control over the Vagrant/VirtualBox machine. I use it not only for "dockering".
Assumptions & Limitations
This CLI tool and its configurations assume that Vagrant's virtual machine provider is VirtualBox. Also, it uses the
VBoxManager to create transient shared folders and to
enable them to create symbolic links. The VirtualBox's User Manual states that "[f]or security reasons the guest OS
is not allowed to create symlinks by default. If you trust the guest OS to not abuse the functionality, you can enable
creation of symlinks (...)" Thus, it is important to notice this warning — and to not abuse that functionality,
for your own safety.
Support & Contributing
If you have found any bug
MIT License © Ewerton Assis