Code Monkey home page Code Monkey logo

docker-sinatra's Introduction

Docker Sinatra

Starter files for running a sinatra app in docker. Great for quick json apis.

Setup

Install Docker

$ brew install docker

boot2docker-xhyve

My preferred way of running docker on OS X is with boot2docker-xhyve.

$ brew install xhyve
$ git clone https://github.com/ailispaw/boot2docker-xhyve
$ cd boot2docker-xhyve
$ make

Install Docker Compose

Though this is a single container application, Docker Compose makes it easy to start and stop docker containers with a shared volume, a specified port, and environment variables.

curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose

Build the docker image

docker-compose build

Start the server

docker-compose up

Your server is now running on port 3000 of your docker ip which you can get from running make ip from within the boot2docker-xhyve directory. It will probably look something like http://192.168.64.2:3000/users.

Notes

Stopping the server

docker-compose stop

Reloading changes

The rerun gem is supposed to help with changes automatically being reloaded but I don't think it is working the way it should. The main server.rb file is using Sinatra Reloader so any changes to server.rb should get picked up. But changes to other files will require a docker-compose stop and docker-compose start which is not ideal.

Forward localhost to docker ip

Because the server is running on the vm, the docker ip is only visible to your machine which means the simulator can talk to it but your external device can not. Luckily it is not to hard to port-forward on mac osx.

  1. Turn on Remote Login in System Preferences -> Sharing
  2. Run the command below replacing the first ip address with your own (192.168.0.102) and the second ip address with your docker ip (192.168.64.21).
ssh -L 192.168.0.102:3000:192.168.64.2:3000 -N 127.0.0.1

The command starts a process that forwards the port. Once you kill the process the port is no longer forwarded which is nice.

docker-sinatra's People

Contributors

armstrongnate avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.