Code Monkey home page Code Monkey logo

vagrant-ansible-docker-django's Introduction

Working with Vagrant, Ansible, and Docker

This is a demo project using Vagrant, Ansbile and Docker. An Ansible playbook is used to build a Docker image, and then start a Docker container. The Docker container runs a Django app which is executed within the Vagrant VM. After successful launch, the django App can be accessed from the host machine via http://localhost:8000.

![Image of Vagrant Environment] (http://oi60.tinypic.com/2zqfpmt.jpg)

Vagrant

Download ubuntu, forward port 8000, and run the Ansible playbook

Vagrant.configure(2) do |config|
  config.vm.box = "raring"
  config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-amd64-vagrant-disk1.box"
  config.vm.network :forwarded_port, host: 8000, guest: 8000
  config.vm.provision "ansible" do |ansible|
    ansible.verbose = 'vvv'
    ansible.playbook = 'playbook.yml'
  end
end

Ansible

Update packages installed on the Vagrant machine, configure ansible role for docker_ubuntu, build the docker image and run it with port 8000

---
- hosts: all
  sudo: yes
  tasks:
    - name: Upgrade VM package manager
      apt: upgrade=dist
    - name: Update package manager sources
      shell: sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
    - name: Run apt-get update
      apt: update_cache=yes

- hosts: all
  sudo: yes
  roles:
    - angstwad.docker_ubuntu
  tasks:
    - name: Build Docker
      shell: docker build -t django_docker /vagrant/
    - name: Run Docker
      docker: image=django_docker ports=8000:8000

Docker

Straightforward dockerfile using ubuntu image, installs Django, exposes port 8000, and runs django app listening to all public requests on port 8000

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y python-pip
RUN pip install Django
RUN django-admin startproject djangodocker
EXPOSE 8000
WORKDIR /djangodocker
CMD python manage.py runserver 0.0.0.0:8000

Required Software

  • Vagrant
  • virtualenv (optional)
  • pip

Up and running


virtualenv env --no-site-packages

source env/bin/activate

pip install -r requirements.txt

ansible-galaxy install angstwad.docker_ubuntu

vagrant up

http://localhost:8000

![Image of Django] (http://oi62.tinypic.com/2yjubly.jpg)

vagrant-ansible-docker-django's People

Contributors

vselvarajijay avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.