Git Product home page Git Product logo

docker-rails-template's Introduction

Docker Rails Template

This is my basic Rails app template for beginning development with Docker.

  • Rails version: 4.2.1
  • Ruby version: 2.2.0

Docker images used:

It runs the application as the app user. The database owner is the myapp_user. To customize this template, grep for myapp and replace all occurrences.

Preparing the Environment

First, decide which environment you wish to use. Copy the selected environment file into .env. For example:

cp .env.development .env

Be sure to define any of the environment variables without values.

Any added environment variables must also be added to rails-env.conf so that they're exposed to Nginx child processes (more info).

Running

Docker Compose is used for linking containers.

First, build the included Dockerfiles:

docker-compose build

Then, start the web app:

docker-compose up

Finally, create the database:

docker exec myapp_web_1 bin/rake db:create

Further commands can be executed in this way.

The app is exposed on port 80 by default. If using Boot2Docker, enter its IP address in your browser.

Sidekiq

This template uses Sidekiq for background processing. A Redis container is linked to enable Sidekiq to work. Once the app is started, Sidekiq provides a monitoring tool at /sidekiq.

To start Sidekiq and process jobs: bin/sidekiq

Sidetiq is used to create scheduled jobs. Scheduled jobs should go under app/workers/scheduled/ and will be automatically loaded even in the development environment.

Testing

For TDD, this template includes the following:

Production

Be sure to create:

  • SECRET_BASE_KEY via bin/rake secret
  • myapp_prod_user with a password for MYAPP_PROD_USER_DATABASE_PASSWORD

Tips

docker-compose up will create a Docker 'web' container named <base-directory-name>_web_1.

The following Bash function:

# ddo -> 'docker-do'
function ddo { docker exec -it `basename $PWD | sed s/[-_]//g`_web_1 $* }

allows:

# Create the database
ddo bin/rake db:create

# Run specs
ddo bin/rspec

# Start a Bash login shell
ddo bash -l

docker-rails-template's People

Contributors

ustasb avatar

Watchers

 avatar  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.