Vagrant: Ubuntu 14.04 with Docker 1.7

Boot2Docker is great however it has some limitations. For instance the OS is readonly and came with pretty much nothing, setting up a shared folder in windows is challenging as well as i showed on last post.  In this post i come to show something different and easier than the previous solution. You can use docker with vagrant if you are a windows or mac user this is better than use boot2docker because IMHO you can do it easily and with less software and you also gain a linux os with you can do stuff because is not read only. Let`s use Vagrant.

Setting up Vagrant

Vagrant will install virtualbox for you the vagrant installation is pretty straightforward, so after you download and install vagrant you just need run $ vagrant init ubuntu/trusty64
Vagrant will create a Vagrantfile for you. It`s a very simple ruby DSL, vagrant allow you to provision a machine using the most cool and modern configuration management / automation engines solutions like Puppet, Chef, Ansible and even Docker.

We will need edit the Vagrantfile in order to install docker for us :-) We also will setup a shared folder with windows, which is very easy, just 1 line of config. So Copy this content and you into your Vagrantfile

Setting up Docker and Docker Compose

Now we can create the machine and do provision with shell, i did not use any of the automation solutions like ansible because this is so straightforward and the shell works for this, however in a production scenario i really recommend you use ansible or chef.

You can realize there is a config for: config.vm.synced_folder this is who we create a shared folder with vagrant  and windows, you just need to have a folder called shared in the same directory you have your Vagrantfile.

The provision happens with shell script, most apt-get install commands, from line 10 to 19. This is happen just once if for same reason you want run them again you can do $ vagrant provision and vagrant will re-run all the shell commands.

You are ready to rock and have fun, now just run $ vagrant up && vagrant ssh
Vagrant will download and install docker 1.7 and docker-compose for you. On the linux machine you can run $ sudo docker run hello-world

Here we go with the inception

That`s all great but lets say i want to run a ubuntu container with docker, well then you just do $ sudo docker run -i -t ubuntu /bin/bash 

Right, but now i want get that windows shared folder i have shared with my vagrant ubuntu linux 14.04 and i want share that with the ubuntu with docker inside vagrant? That`s piece of cake now, docker has the -v option you can map shared folders, you just need do this:
$ sudo docker run -v /home/vagrant/shared/:/home/ubuntu/shared -i -t ubuntu /bin/bash

IF you want all the files you can download from my git hub

Diego Pacheco

Popular posts from this blog

Kafka Streams with Java 15

Rust and Java Interoperability

HMAC in Java