├── .gitignore ├── README.md ├── Vagrantfile ├── conf ├── Dockerfile ├── index.html ├── inventory-file └── provision.yml └── provision-vagrant.yml /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Install 2 | The following assumes you already have _vagrant_ and _ansible_ installed on your local machine. 3 | 4 | On your local machine, run: 5 | 6 | vagrant up 7 | 8 | The _Vagrantfile_ is configured to start a VM with 2GB of ram and will provision all the pre-requisites to run docker provisioned by Ansible locally on the VM. 9 | It will also copy the files in the _conf_ directory onto the Docker host VM that is created, so you can run Docker from there. 10 | 11 | Get on to the vagrant VM by running: 12 | 13 | vagrant ssh 14 | 15 | ## Working with Docker on your Vagrant VM 16 | Building the docker image given the Docker file and provision.yml Ansible script: 17 | 18 | sudo docker build . 19 | 20 | After this, you'll get an image id, which you can use in the following command: 21 | 22 | sudo docker run -d -p 80:80 -v /home/vagrant/html:/usr/share/nginx/html [image id] 23 | 24 | 25 | This will start the image in a new Docker container in daemon mode (it will not die straight after starting nginx), with the container port 80 mapped to the hosts port 80. 26 | Further more, it will mount the /home/vagrant/html directory on the host as the nginx html directory on the container. 27 | 28 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | 6 | 7 | Vagrant.configure("2") do |config| 8 | # All Vagrant configuration is done here. The most common configuration 9 | # options are documented and commented below. For a complete reference, 10 | # please see the online documentation at vagrantup.com. 11 | 12 | # Every Vagrant virtual environment requires a box to build off of. 13 | # config.vm.box = "ubuntu/trusty64" 14 | 15 | config.vm.define "docker" do |docker| 16 | docker.vm.box = "ubuntu/trusty64" 17 | docker.vm.network "private_network", ip: "192.168.93.255" 18 | docker.vm.provider "virtualbox" do |v| 19 | v.memory = 2048 20 | v.cpus = 1 21 | end 22 | end 23 | 24 | # can this be by box? eg jenkins.vm.provider instead of config.vm.provider? 25 | # config.vm.provider "virtualbox" do |v| 26 | # v.memory = 1024 27 | # v.cpus = 1 28 | # end 29 | 30 | config.vm.provision "ansible" do |ansible| 31 | ansible.playbook = "provision-vagrant.yml" 32 | end 33 | 34 | # Disable automatic box update checking. If you disable this, then 35 | # boxes will only be checked for updates when the user runs 36 | # `vagrant box outdated`. This is not recommended. 37 | # config.vm.box_check_update = false 38 | 39 | # Create a public network, which generally matched to bridged network. 40 | # Bridged networks make the machine appear as another physical device on 41 | # your network. 42 | # config.vm.network "public_network" 43 | 44 | # If true, then any SSH connections made will enable agent forwarding. 45 | # Default value: false 46 | # config.ssh.forward_agent = true 47 | 48 | # Share an additional folder to the guest VM. The first argument is 49 | # the path on the host to the actual folder. The second argument is 50 | # the path on the guest to mount the folder. And the optional third 51 | # argument is a set of non-required options. 52 | # config.vm.synced_folder "../data", "/vagrant_data" 53 | 54 | # Provider-specific configuration so you can fine-tune various 55 | # backing providers for Vagrant. These expose provider-specific options. 56 | # Example for VirtualBox: 57 | # 58 | # config.vm.provider "virtualbox" do |vb| 59 | # # Don't boot with headless mode 60 | # vb.gui = true 61 | # 62 | # # Use VBoxManage to customize the VM. For example to change memory: 63 | 64 | 65 | end 66 | -------------------------------------------------------------------------------- /conf/Dockerfile: -------------------------------------------------------------------------------- 1 | # Version: 0.0.1 2 | FROM ubuntu:14.04.1 3 | MAINTAINER Wille Faler "wfaler@recursivity.com" 4 | 5 | RUN apt-get update 6 | RUN apt-get install -y software-properties-common 7 | RUN apt-add-repository ppa:ansible/ansible 8 | RUN apt-get update 9 | RUN apt-get install -y ansible 10 | add inventory-file /etc/ansible/hosts 11 | ADD provision.yml provision.yml 12 | RUN ansible-playbook provision.yml -c local 13 | RUN echo "daemon off;" >> /etc/nginx/nginx.conf 14 | 15 | EXPOSE 80 16 | CMD ["nginx"] -------------------------------------------------------------------------------- /conf/index.html: -------------------------------------------------------------------------------- 1 | Hello world, I'm in your docker! -------------------------------------------------------------------------------- /conf/inventory-file: -------------------------------------------------------------------------------- 1 | [local] 2 | localhost -------------------------------------------------------------------------------- /conf/provision.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: local 3 | 4 | tasks: 5 | # already done by Dockerfile 6 | # - name: ensure apt cache is updated 7 | # action: apt update_cache=yes 8 | 9 | - name: ensure all software is installed 10 | action: apt name={{item}} 11 | with_items: 12 | - nginx -------------------------------------------------------------------------------- /provision-vagrant.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: all 3 | sudo: yes 4 | # run with ansible-playbook register-key.yml -i hosts --ask-pass --ask-sudo-pass -u [your username] --extra-vars "user=[your username]" 5 | 6 | tasks: 7 | - name: add user ubuntu 8 | user: name=ubuntu 9 | groups="admin,ubuntu" 10 | 11 | - name: register key for user ubuntu 12 | action: authorized_key user='ubuntu' key="{{ lookup('file', '~/.ssh/id_rsa.pub') }}" 13 | 14 | - name: ensure apt cache is updated 15 | action: apt update_cache=yes 16 | 17 | - name: ensure all software is installed 18 | action: apt name={{item}} 19 | with_items: 20 | - emacs24 21 | - tmux 22 | - docker.io 23 | - curl 24 | 25 | - name: ensure docker is linked 26 | shell: ln -sf /usr/bin/docker.io /usr/local/bin/docker creates=/usr/local/bin/docker 27 | 28 | - name: create directory to be shared between host and container 29 | shell: mkdir -p /home/vagrant/html creates=/home/vagrant/html 30 | 31 | - name: ensure docker is started on startup 32 | shell: update-rc.d docker.io defaults 33 | 34 | - name: copy over the index.html file to be served by the Docker container 35 | action: copy src=conf/index.html dest=/home/vagrant/html/index.html 36 | 37 | - name: copy over the Dockerfile 38 | action: copy src=conf/Dockerfile dest=/home/vagrant/Dockerfile 39 | 40 | - name: copy over the Ansible file with which we provision the Docker container 41 | action: copy src=conf/provision.yml dest=/home/vagrant/provision.yml 42 | 43 | - name: copy over the inventory file for Dockers Ansible provisioning 44 | action: copy src=conf/inventory-file dest=/home/vagrant/inventory-file --------------------------------------------------------------------------------