Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Virtuelle Umgebungen mit Vagrant, Docker und An...

Simon Olofsson
September 05, 2014

Virtuelle Umgebungen mit Vagrant, Docker und Ansible (c4tt)

Slides zu meinem Vortrag auf den c4tt September 2014.
http://lanyrd.com/2014/dhf/sdcxbw/
https://github.com/simono/vm-examples

Simon Olofsson

September 05, 2014
Tweet

More Decks by Simon Olofsson

Other Decks in Technology

Transcript

  1. ! % vagrant up Bringing machine 'default' up with 'virtualbox'

    provider… % vagrant ssh % vagrant destroy ==> default: Destroying VM and associated drives...
  2. Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" ! config.vm.network "forwarded_port", guest:

    80, host: 8080 ! config.vm.provision "shell", inline: "sudo apt-get -y install nginx" end
  3. Übernommen von http://www.docker.com/whatisdocker/ Applikation A Binaries/ Libraries Guest OS Applikation

    B Binaries/ Libraries Guest OS Hypervisor Host OS Server }Virtuelle Machine
  4. Vagrant.configure("2") do |config| ! config.vm.provider "docker" do |d| d.image =

    "nginx" d.ports = ["8080:80"] d.vagrant_vagrantfile = "../docker-host/Vagrantfile" end end
  5. Vagrant.configure("2") do |config| ! config.vm.box = "mitchellh/boot2docker" ! config.vm.network "forwarded_port",

    guest: 7070, host: 7070 ! config.vm.network "forwarded_port", guest: 8080, host: 8080 ! end
  6. ! % vagrant up --provider=docker Bringing machine 'default' up with

    'docker' provider… ==> default: Docker host is required. One will be created if necessary… ==> default: Creating the container… ==> default: Starting container...
  7. Vagrant.configure("2") do |config| ! config.vm.provider "docker" do |d| d.image =

    "node" d.cmd = ["node", "/vagrant/app.js"] d.ports = ["8080:80"] d.vagrant_vagrantfile = "../docker-host/Vagrantfile" end end
  8. var http = require('http'); ! var server = http.createServer(function (request,

    response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end( "Hello c4tt from Node!\n"); }); ! server.listen(80);
  9. FROM debian:jessie ! RUN apt-get update && apt-get install -y

    … ! ADD . /usr/src/nginx WORKDIR /usr/src/nginx ! RUN ./configure … RUN make … RUN make install … ! WORKDIR /usr/local/nginx/html ! EXPOSE 80 CMD ["nginx"] Übernommen von https://github.com/docker-library/nginx/blob/docker-v1.7.1/Dockerfile
  10. Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" ! config.vm.network "forwarded_port", guest:

    80, host: 8080 ! config.vm.provision "ansible" do | ansible| ansible.playbook = "playbook.yml" end end
  11. --- - hosts: all sudo: yes tasks: - name: Install

    nginx apt: name=nginx state=latest - name: Ensure nginx is started service: name=nginx state=started
  12. ! % vagrant up Bringing machine 'default' up with 'virtualbox'

    provider… ==> default: Running provisioner: ansible… default: ok=3 changed=1 % vagrant provision ==> default: Running provisioner: ansible… default: ok=3 changed=0
  13. config.vm.define "db" do |db| db.vm.provider "docker" do |d| d.name =

    "db" d.cmd = ["/sbin/my_init", "--enable-insecure-key"] d.image = "phusion/passenger-full" d.expose = [5432] d.has_ssh = true d.vagrant_vagrantfile = "../docker-host/Vagrantfile" end ! db.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" end # SSH Setup gekürzt… end
  14. --- - hosts: db sudo: yes tasks: - name: Install

    postgresql apt: name={{item}} state=latest with_items: - postgresql - python-psycopg2 - name: Ensure postgresql is started service: name=postgresql state=started - name: Create postgresql DB sudo_user: postgres postgresql_db: name=app_db
  15. config.vm.define "app" do |app| app.vm.provider "docker" do |d| d.name =

    "app" d.image = "node" d.cmd = ["node", "/vagrant/app.js"] d.ports = ["7070:80"] d.link("db:db") d.vagrant_vagrantfile = "../docker-host/Vagrantfile" end end
  16. config.vm.define "assets" do |assets| assets.vm.provider "docker" do |d| d.name =

    "assets" d.image = "nginx" d.ports = ["8080:80"] d.vagrant_vagrantfile = "../docker-host/Vagrantfile" end ! assets.vm.synced_folder ".", "/usr/local/nginx/html", :mount_options => ["ro"] ! end
  17. Vielen Dank! Simon Olofsson • Content Management AG @solofs •

    [email protected] Die Logos wurden den Webseiten der jeweiligen Projekte entnommen.