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 https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/DevOps/vagrant-with-docker
Cheers,
Diego Pacheco
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.configure(2) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.network "private_network", ip: "55.55.55.100" | |
config.vm.synced_folder "shared", "/home/vagrant/shared/" | |
config.vm.provision "shell", inline: <<-SHELL | |
sudo apt-get update | |
sudo apt-get install -y lxc | |
sudo apt-get install -y wget | |
sudo wget -qO- https://get.docker.com/ | sudo bash | |
sudo apt-get install -y curl | |
sudo apt-get install -y git | |
sudo curl -L https://github.com/docker/compose/releases/download/1.3.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
SHELL | |
end |
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 https://github.com/diegopacheco/Diego-Pacheco-Sandbox/tree/master/DevOps/vagrant-with-docker
Cheers,
Diego Pacheco