Rails Tips #2 Dockerizing Rails app

Dockerfile

# Ruby on Rails Development Environment
FROM ruby:2.5.0

# Set up Linux
RUN apt-get update
RUN apt-get install -y build-essential inotify-tools libpq-dev nodejs libmariadbclient-dev

WORKDIR /app
EXPOSE 3000

docker-compose.yml

version: '3.2'
services:
 db:
   image: mariadb
 environment:
   MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
 web:
   build: .
   volumes:
     - type: bind
       source: .
       target: /app
   ports:
     - "3000:3000"
   depends_on:
     - db
 command:
   - ./run.sh

config/database.yml

development:
 adapter: mysql2
 encoding: utf8
 database: blog
 username: root
 host: db
 port: 3306

Gemfile

gem 'mysql2'

run.sh

#!/bin/sh
set -e

# Ensure the app's dependencies are installed
echo "bundle install --without=production..."
bundle install --without=production

# Potentially Set up the database
echo "bundle exec rake db:setup..."
bin/rails db:setup

# Start the web server
echo "bin/rails s -p 3000 -b '0.0.0.0'..."
bin/rails s -p 3000 -b '0.0.0.0'

권한 바꾸기

$ chmod +x run.sh

도커 컴포저 실행하기

$ docker-compose up

 

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다