This project is indented as an example how to combine a Sinatra app serving a JSON API with both Docker and ActiveRecord. It has been developed as part of a blog series on this topic. You can read the articles here:
- Part 1: Dockerizing Sinatra
- Part 2: Making Docker an art with Compose
- Part 3: How to set up Sinatra with ActiveRecord
- Part 4: Dockerized databases with Sinatra
The Sinatra app is inside the directory
/app. It consists of a
declaring its dependencies, a rackup file
config.ru and the actual application
It also uses a database that is provided by the official PostgreSQL image. Using docker-compose, both containers can be started simultaneously.
You can use docker-compose to start the application. The following command starts all containers:
$ docker-compose up
If you want to inspect the database, you can connect to it using psql:
psql -U sinatra sinatra
Copyright (c) 2016 Jan David Nose
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.