a Code Farmer

A blogging framework for hacker who farms

Hello Sinatra

The setup

I choose to take recently most popular technology - Docker as our testing environment. One of benefit features of docker is that by using Dockerfile we have a descriptive and vcs-capable system environment, and that makes our life easier when we have migration needs.

Project Structure
1
2
3
4
5
/PROJECT_HOME/
├── Dockerfile
└── myapp.rb

0 directories, 2 files

Easy enough, just two files.

Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# It’ll need ruby
FROM ruby:latest

MAINTAINER sabonis <sabonis.tw@gmail.com>

# The directory our main program` runs on.
VOLUME /server

# Relative path in which command executes.
WORKDIR /server

# Install sinatra
RUN gem install sinatra

# Defaut host of sinatra app is 127.0.0.1,
# that is not OK if your server needs port-forwarding.
CMD ruby myapp.rb -o 0.0.0.0

EXPOSE 4567
myapp.rb
1
2
3
4
5
6
#myapp.rb
require 'sinatra'

get '/' do
  'Hello world!'
end

The Hello

Console
1
2
3
4
5
6
7
8
9
10
11
12
# Build dockerfile to docker image.
sudo docker build -t YOUR_NAME/sinatra

# Run the image.
sudo docker run -dp 80:4567 \
                -v `pwd`:/server \
                YOUR_NAME/sinatra

# Test whether it works.
curl localhost
Hello world!%
#It works.

Comments