├── Procfile ├── config.ru ├── .gitignore ├── Gemfile ├── Brewfile ├── app.rb ├── Vagrantfile ├── Dockerfile └── README.md /Procfile: -------------------------------------------------------------------------------- 1 | web: bundle exec rackup config.ru -p 4567 -s thin -o 0.0.0.0 -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | $:.unshift(File.dirname(__FILE__)) 2 | 3 | require 'app' 4 | run App -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Gemfile.lock 2 | .ruby-version 3 | .vagrant/ 4 | .bundle/ 5 | vendor/ -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'foreman' 4 | gem 'sinatra' 5 | gem 'thin' 6 | -------------------------------------------------------------------------------- /Brewfile: -------------------------------------------------------------------------------- 1 | # Install homebrew-cask 2 | tap phinze/homebrew-cask 3 | install brew-cask 4 | 5 | # Install virtualbox and vagrant 6 | cask install virtualbox 7 | cask install vagrant -------------------------------------------------------------------------------- /app.rb: -------------------------------------------------------------------------------- 1 | require 'sinatra' 2 | require 'sinatra/base' 3 | 4 | class App < Sinatra::Base 5 | get '/' do 6 | 'Hello from docker!' 7 | end 8 | end 9 | 10 | 11 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! 5 | VAGRANTFILE_API_VERSION = "2" 6 | 7 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 8 | config.vm.box = "precise64" 9 | config.vm.network :forwarded_port, guest: 4567, host: 4567 10 | config.vm.provision :docker do |d| 11 | d.pull_images "ubuntu" 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM base 2 | 3 | MAINTAINER tcnksm "https://github.com/tcnksm" 4 | 5 | # Install packages for building ruby 6 | RUN apt-get update 7 | RUN apt-get install -y --force-yes build-essential wget git 8 | RUN apt-get install -y --force-yes zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev 9 | RUN apt-get clean 10 | 11 | RUN wget -P /root/src http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz 12 | RUN cd /root/src; tar xvf ruby-2.2.2.tar.gz 13 | RUN cd /root/src/ruby-2.2.2; ./configure; make install 14 | 15 | RUN gem update --system 16 | RUN gem install bundler 17 | 18 | RUN git clone https://github.com/tcnksm/docker-sinatra /root/sinatra 19 | RUN cd /root/sinatra; bundle install 20 | 21 | EXPOSE 4567 22 | CMD ["/usr/local/bin/foreman","start","-d","/root/sinatra"] 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Runing a sinatra application on Docker 2 | 3 | This is sample project for running a sinatra application on Docker. 4 | 5 | ## Usage 6 | 7 | Create Image 8 | 9 | ``` 10 | docker build -t sinatra . 11 | ``` 12 | 13 | Run it ! 14 | 15 | ``` 16 | ID=$(docker run -p 4567:4567 -d sinatra) 17 | ``` 18 | 19 | You can access it from your browser, [http://localhost:4567/](http://localhost:4567/). 20 | 21 | Check logs. 22 | 23 | ``` 24 | docker logs $ID 25 | ``` 26 | 27 | Stop it. 28 | 29 | ``` 30 | docker stop $ID 31 | ``` 32 | 33 | Delete it. 34 | 35 | ``` 36 | docker rm $ID 37 | ``` 38 | 39 | ## OS X 40 | 41 | Use Vagrant. In `Vagrantfile`, just add port forwarding settings. 42 | 43 | ``` 44 | vagrant up 45 | ``` 46 | 47 | and 48 | 49 | ``` 50 | vagrant ssh 51 | ``` 52 | 53 | ## Reference 54 | 55 | - [OSX, Vagrant, Docker, and Sinatra | DYLI.SH](http://dyli.sh/2013/08/23/OSX-Vagrant-Docker-Sinatra.html) 56 | - [Sinatra deployment with Docker](http://haanto.com/sinatra-deployment-with-docker/) 57 | 58 | 59 | --------------------------------------------------------------------------------