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

[トレタ社内勉強会 "Dockerの上でRailsアプリを動かす ハンズオン

[トレタ社内勉強会 "Dockerの上でRailsアプリを動かす ハンズオン

Yuichiro MASUI

April 13, 2016
Tweet

More Decks by Yuichiro MASUI

Other Decks in Programming

Transcript

  1. Docker Machine Host OS ϓϩηε ϓϩηε ϑΝΠϧγεςϜ Docker daemon VirtualBox

    OSX / Windows Docker Machine ϓϩηε FS ϓϩηε FS Network Network
  2. DockerͰγΣϧىಈ • “Docker Quickstart Terminal”Λ3ຕىಈ • docker run -it ubuntu:14.04

    /bin/bash • ps aux • touch /abc123 • docker run -it ubuntu:14.04 /bin/bash • ls / • docker ps
  3. ͳʹ͕ى͍ͬͯ͜Δ͔ • docker run -it ubuntu:14.04 /bin/bash • “ubuntu:14.04” ࣮ߦ͢ΔϑΝΠϧΠϝʔδ

    • ϩʔΧϧʹͳ͍৔߹͸μ΢ϯϩʔυ • ΠϝʔδΛల։͠DockerͰىಈ • “-it” ίϯιʔϧΛܨ͛Δ
  4. ࣗ෼ͷΠϝʔδΛ࡞Δ • ΠϝʔδʹมߋΛՃ͑Δ • Dockerfile FROM ubuntu:14.04 RUN apt-get update

    RUN apt-get install -y apache2 CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
  5. DockfileΛىಈ • docker build -t myapache ./ • “-t myapache”

    Πϝʔδ໊ • “./“ DockerfileͷσΟϨΫτϦ • docker run -p 8080:80 myapache • http://192.168.99.100:8080 • docker-machine ip
  6. docker-compose.yml rails:
 build: .
 command: [“./bin/rails","server","-b","0.0.0.0"]
 mem_limit: 512m
 ports:
 -

    "3000:3000"
 volumes:
 - ".:/usr/src/app"
 links:
 - "mysql" mysql:
 image: mysql:5.6
 environment:
 MYSQL_ROOT_PASSWORD: "passwd"
  7. database.yml • default: &default
 adapter: mysql2
 username: root
 password: "passwd"


    host: mysql • production:
 <<: *default
 host: <%= ENV[‘MYSQL_HOST'] %>
 ↑͜ͷߦΛ௥Ճ
  8. scaffold • docker-compose up -d • docker-compose run rails /bin/bash

    • rails g scaffold item key:string value:text • rake db:create db:migrate • http://192.168.99.100:3000/items • docker-compose stop
  9. Amazon ECS & ECR • Amazon EC2 Container System •

    Dockerͱecs-agentೖΓઐ༻ͷAMI • DockerΛૢ࡞͢Δίϯιʔϧ & API • Amazon EC2 Container Registry • Docker Registry
  10. ECRʹimageΛpush • $(aws ecr get-login --region us-east-1) • docker build

    -t sample1 . • docker tag sample1:latest 123456.dkr.ecr.us- east-1.amazonaws.com/sample1:latest • docker push 123456.dkr.ecr.us- east-1.amazonaws.com/sample1:latest