docker as development environment
TRANSCRIPT
Bruno de Lima e Silva
Games Graduate degree in mobile Parto Humanizado Crowdmobi, Trakto Qviky Coding Dojo
Docker as Development Environment
VirtualizationVirtualization What is It?
VirtualizationVirtualization Inception
VirtualizationVirtualization Why I should use it?
VirtualizationVirtualization You don't need to install everything
VirtualizationVirtualization Maintenance
VirtualizationVirtualization How to do it?
● What?● “Here it works”, who’s never?● New team member● Provision != drean● Overhead
Same as production environment
Docker
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?
Docker How it works?● Docker Hub● Images● Build Images● Share host resources
Docker Is it better?
Docker How run docker commands
docker run <image> command
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’
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’);
● 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
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
● 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
Docker-Compose
● Compose multiple containers● Just configure it ● Run a single command
Docker-Compose
docker-compose up
Sampleweb: build: . ports: - "5000:5000" volumes: - .:/code links: - redisredis: image: redis
Docker-Compose
Ruby and Rails On Dockercompose
db: image: postgres ports: - "5432:5432" environment: - POSTGRES_USER=postgres - POSTGRES_PASS=postgres
Ruby and Rails Start from DB
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
#!/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
box: image: busybox volumes: - /box
Ruby and Rails Add busybox
web: &default build: . command: ./script/start.sh volumes: - .:/usr/src/app volumes_from: - box ports: - "3000:3000" links: - db
Ruby and Rails Create web
worker: << *default command: bundle exec rake jobs:work
Ruby and Rails Create workers
mailcatcher: hostname: mailcatcher image: "schickling/mailcatcher" command: mailcatcher -f --ip=0.0.0.0 ports: - "1080:1080" - "1025:1025"
Ruby and Rails Create MailCatcher
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
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
+BrunoDeLimaS
Bruno de Lima
@brunodles
That’s all folksThat’s all folks+BrunoDeLimaS
Bruno de Lima
@brunodles
https://github.com/Padawan-org/Padawan-Docker