docker as development environment

34

Upload: bruno-de-lima-e-silva

Post on 16-Apr-2017

403 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Docker as development environment
Page 2: Docker as development environment

Bruno de Lima e Silva

Games Graduate degree in mobile Parto Humanizado Crowdmobi, Trakto Qviky Coding Dojo

Page 3: Docker as development environment

Docker as Development Environment

Page 4: Docker as development environment

VirtualizationVirtualization What is It?

Page 5: Docker as development environment

VirtualizationVirtualization Inception

Page 6: Docker as development environment

VirtualizationVirtualization Why I should use it?

Page 7: Docker as development environment

VirtualizationVirtualization You don't need to install everything

Page 8: Docker as development environment

VirtualizationVirtualization Maintenance

Page 9: Docker as development environment

VirtualizationVirtualization How to do it?

Page 10: Docker as development environment

● What?● “Here it works”, who’s never?● New team member● Provision != drean● Overhead

Same as production environment

Page 11: Docker as development environment

Docker

Page 12: Docker as development environment

Docker

“Docker containers wrap up a piece of software in a complete filesystem that contains everything it needs to run: code, runtime, system tools, system libraries –

anything you can install on a server. This guarantees that it will always run the same, regardless of the environment it is running in.” - Docker docs

What is it?

Page 13: Docker as development environment

Docker How it works?● Docker Hub● Images● Build Images● Share host resources

Page 14: Docker as development environment

Docker Is it better?

Page 15: Docker as development environment

Docker How run docker commands

docker run <image> command

Page 16: Docker as development environment

Docker and Ruby● Create a ruby file (hello.rb), with this:

● Run it with docker

docker run --rm -v "$(pwd)":/app -w /app ruby:2.2 'ruby hello.rb'

puts ‘The Power of Docker’

Page 17: Docker as development environment

and Node● Create a node file (hello.js), with this:

● Run it with docker

Docker

docker run --rm -v "$(pwd)":/app -w /app node 'node hello.js'

console.log(‘Node works too’);

Page 18: Docker as development environment

● To link the app we need to start postgres and give it a name

● Then, start the app linking it to postgres

Docker

docker run -d --name db -e POSTGRES_PASSWORD=123456 postgres

docker run -d -P --link db:dbLink image command

and PostgreSql

Page 19: Docker as development environment

FROM ruby:2.2

RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*ENV RAILS_VERSION 4.2.3RUN gem install rails --version $RAILS_VERSION

WORKDIR $appADD . $app

EXPOSE 3000CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]

Dockerfile

Page 20: Docker as development environment

● Lots of commands● Lots of params● I don’t want to remember that all just to run the app● and that Dockerfile

Docker is getting harder

Page 21: Docker as development environment

Docker-Compose

Page 22: Docker as development environment

● Compose multiple containers● Just configure it ● Run a single command

Docker-Compose

docker-compose up

Page 23: Docker as development environment

Sampleweb: build: . ports: - "5000:5000" volumes: - .:/code links: - redisredis: image: redis

Docker-Compose

Page 24: Docker as development environment

Ruby and Rails On Dockercompose

Page 25: Docker as development environment

db: image: postgres ports: - "5432:5432" environment: - POSTGRES_USER=postgres - POSTGRES_PASS=postgres

Ruby and Rails Start from DB

Page 26: Docker as development environment

FROM ruby:2.2RUN apt-get update && apt-get install -y nodejs mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*ENV RAILS_VERSION 4.2.3RUN gem install rails --version $RAILS_VERSIONENV app /usr/src/appRUN mkdir $appWORKDIR $appENV BUNDLE_PATH /boxADD . $appEXPOSE 3000CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]

Ruby and Rails Create app image

Page 27: Docker as development environment

#!/bin/bash

bundle check || bundle install

bundle exec rails s -b 0.0.0.0 -p 3000

rm -f tmp/pids/server.pid

Ruby and Rails Create app start script

Page 28: Docker as development environment

box: image: busybox volumes: - /box

Ruby and Rails Add busybox

Page 29: Docker as development environment

web: &default build: . command: ./script/start.sh volumes: - .:/usr/src/app volumes_from: - box ports: - "3000:3000" links: - db

Ruby and Rails Create web

Page 30: Docker as development environment

worker: << *default command: bundle exec rake jobs:work

Ruby and Rails Create workers

Page 31: Docker as development environment

mailcatcher: hostname: mailcatcher image: "schickling/mailcatcher" command: mailcatcher -f --ip=0.0.0.0 ports: - "1080:1080" - "1025:1025"

Ruby and Rails Create MailCatcher

Page 32: Docker as development environment

https://medium.com/iron-io-blog/why-and-how-to-use-docker-for-development-a156c1de3b24#.injn4gk15

http://gutocarvalho.net/octopress/2014/05/09/entenda-o-vagrant/

https://nandovieira.com.br/usando-o-vagrant-como-ambiente-de-desenvolvimento-no-windows

https://www.thoughtworks.com/pt/insights/blog/puppet-and-vagrant-how-provision-machines-your-project

Fonts

Page 33: Docker as development environment

http://www.atlashealth.com/blog/2014/09/persistent-ruby-gems-docker-container/#.VlJ5ICCrS00

https://medium.com/@fbzga/how-to-cache-bundle-install-with-docker-7bed453a5800#.b7oq8rnxc

https://github.com/treeder/docker-for-development

Fonts

Page 34: Docker as development environment

+BrunoDeLimaS

Bruno de Lima

@brunodles

That’s all folksThat’s all folks+BrunoDeLimaS

Bruno de Lima

@brunodles

https://github.com/Padawan-org/Padawan-Docker