项目作者: jianghan0

项目描述 :
A lightweight Docker images set for API mode of Rails applications.
高级语言: Dockerfile
项目地址: git://github.com/jianghan0/docker-rails5-alpine.git
创建时间: 2019-06-20T14:48:02Z
项目社区:https://github.com/jianghan0/docker-rails5-alpine

开源协议:

下载


docker-rails5-alpine

Introduction

Docker-rails5-alpine is lightweight Docker images set for Rails applications based on Alpine Linux. This is optimzed for the API mode using MySQL and Redis.

Environment

  • ruby: 2.6.3
  • mysql: 8.0.16
  • redis: 5.0.5

How to use

Clone this repository

  1. git clone https://github.com/jianghan0/docker-rails5-alpine.git

Add rails code to source directory

  1. cd docker-rails5-alpine
  2. # When use your exist rails app
  3. git clone (your-rails-repository) source
  4. # When create new rails app
  5. mkdir source && cd source
  6. rails new . --api --mysql

Edit your database settings

  1. # config/database.yml
  2. default: &default
  3. adapter: mysql2
  4. encoding: utf8
  5. pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  6. host: <%= ENV.fetch("DB_HOST") { "127.0.0.1" } %>
  7. port: <%= ENV.fetch("DB_PORT") { 3306 } %>
  8. username: <%= ENV.fetch("DB_USER") { root } %>
  9. password: <%= ENV.fetch("DB_PASSWORD") %>
  10. development:
  11. <<: *default
  12. database: your-database

Build docker image

  1. docker-compose build

Create database and run the migrations

  1. docker-compose run --rm web bin/rails db:create
  2. docker-compose run --rm web bin/rails db:migrate

Run the app

  1. docker-compose up -d

Attach rails server

  1. docker attach docker-rails5-alpine_web_1

Then you can access your rails app by localhost:3000