Cool, now lets try a full example. Lets say we have a passenger
+ ruby
and a database webapp.
Lets put this Dockerfile
into a new folder:
FROM litaio/ruby
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
RUN apt-get install -y apt-transport-https ca-certificates
RUN echo "deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main" >> /etc/apt/sources.list
RUN apt-get update -qq
RUN apt-get install -y passenger
RUN gem install rack daemon_controller sinatra --no-ri --no-rdoc
WORKDIR /app
EXPOSE 3000
VOLUME ["/app"]
This base image, litaio/ruby
already has build out Ruby 2.1.2 for us. You can check out that images Dockerfile here.
You also need to create a file called config.ru
in that folder:
run Proc.new {|env| [200, {"Content-Type" => "text/html"}, ["Hello Rack!"]]}
And lets see if it works:
$ docker build -t workshop/full .
...
$ docker run -i -p 3000:3000 -v $(pwd):/app -t workshop/full passenger start
If you don't get any errors, navigate to http://your-ip:3000
Sinatra is a nice little webframework with minial configuration. Lets replace our config.ru
with:
require 'rubygems'
require './app'
run Sinatra::Application
We also need our Sinatra code in app.rb
:
require 'sinatra'
get '/' do
"Hello from Sinatra!"
end
$ docker run -i -p 3000:3000 -v $(pwd):/app -t workshop/full passenger start
If you don't get any errors, navigate to http://your-ip:3000
Lets start a database:
$ docker run -d --name db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root orchardup/mysql
...
$ mysql -uroot -h127.0.0.1 -proot
mysql> show databases;
...
The exercises below will have you link the two containers up.
/add
, list records on /
workshop/full
to allow docker run -t workshop/full
to serve the app.