Skip to content

Instantly share code, notes, and snippets.

@usergenic
Created March 6, 2019 00:30
Show Gist options
  • Save usergenic/22939cd68be8705f9ef78fd018863149 to your computer and use it in GitHub Desktop.
Save usergenic/22939cd68be8705f9ef78fd018863149 to your computer and use it in GitHub Desktop.
With just these three files, you can run a sinatra app with redis using Docker.
require 'sinatra'
require 'redis'
set :bind, '0.0.0.0'
Cache = Redis.new(host: 'redis', port: 6379)
def get_hit_count
Cache.incr('hits')
end
get '/' do
"Hello World! I have been hit #{get_hit_count} times.\n"
end
version: '3'
services:
web:
build: .
ports:
- "4567:4567"
volumes:
- .:/code
redis:
image: "redis:alpine"
FROM ruby:2.5.1-alpine
WORKDIR /code
RUN gem install sinatra
RUN gem install redis
CMD ["ruby", "app.rb"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment