Here is an easy guide on how to manage container Docker with Vagrant. This guide is tested on Rackspace Cloud Server and will work on all OpenStack IaaS. We already know what is Container Based Virtualization and how to use Docker on Cloud Server to Manage Containers. It is actually possible to Manage Docker with Vagrant on OpenStack Cloud Server – “Vagrant 1.6 comes with a new built-in provider: Docker”. We can not say whether it is possible to do with OpenShift Origin.
Disambiguation of the Names : OpenShift is Open Source PaaS software by RedHat, while OpenStack is intended for IaaS, initially developed by NASA and Rackspace. OpenShift can run on OpenStack, vice versa is not possible.
Manage Docker with Vagrant on OpenStack Cloud Server : Get Started
We will get started by installing Vagrant 1.6.x and Docker 1.1.x on Ubuntu Trusty (14.04 LTS) on Rackspace Performance 1 Flavor (PVHVM). While PVHVM is used for better performance, usage of 2GB instance (at this moment of publishing this article) will provide virtual dual core processor. Assuming that we are using a Mac (OS X 10.9.x) or any GNU Linux, we can use Docker on local computing via Boot2Docker :
---
1 2 3 4 | # official instructions https://docs.docker.com/installation/mac/ # github repo https://github.com/boot2docker/boot2docker |
Boot2Docker uses a Vagrant VirtualBox VM with Docker on it. As post installation process, we will set the environment variable VAGRANT_DEFAULT_PROVIDER
:
1 2 3 4 5 6 | # edit using nano export VAGRANT_DEFAULT_PROVIDER=docker # check version manually wget https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3_x86_64.deb && dpkg -i vagrant_1.6.3_x86_64.deb # we are working via SSH - make sure that you have understood our plan sudo apt-get install lxc-docker-1.1.1 |
We did it, so that Vagrant is forced to use Docker by default.
Example of How We Can Manage Docker with Vagrant
We can create a vagrantfile
to manage our Docker container based on this list of cookbook :
1 2 3 | https://github.com/Krijger/docker-cookbooks # example with mongo db https://github.com/Krijger/docker-cookbooks/tree/master/mongo |
You can use any of the recipe to test (or taste!). You can read about Vagrant configuration :
1 | https://docs.vagrantup.com/v2/providers/configuration.html |
If there is any problem with Path on VM (in case it is local computer), go to /vagrant/scripts
and add the following line on setup.sh
file :
1 | echo "source /vagrant/scripts/export.sh" >> /home/vagrant/.bashrc |
Below is an example vagrantfile
, but look at the Docker hub first :
1 | https://registry.hub.docker.com/u/quintenk/mongo/ |
This is an edited vagrantfile
for mongo :
1 2 3 4 5 6 7 8 9 10 | Vagrant.configure("2") do |config| config.vm.provider "docker" do |d| d.image = "quintenk/mongo" d.has_ssh = false d.ports = ["27017:27017"] d.volumes = ["/data/mongo:/root/.mongo"] end end |
For VM (local computer), the vagrant file might need some alteration.
This file contains a single configuration block as per documentation. docker
notation declares a Docker instance and variable name is d
, simply run Vagrant :
1 | vagrant up |
Note that, this IS A COMPLICATED example as it is mongo db and port can not be 8080. You can start with any cookbook which uses the port 8080.
Tagged With cloud computing tutorial , install docker cloud on boot2docker , openstack owncloud docker , ssh boot2docker cloud-config , vagrant file edit docker config , vagrant openstack get_api_version error