LoginSignup
0
0

More than 3 years have passed since last update.

Rails開発環境Template

Last updated at Posted at 2020-08-22

プロジェクトフォルダの作成

build context内に以下のファイルを作成

Dockerfile
Gemfile
Gemfile.lock
docker-compose.yml

Dockerfileを編集

Dockerfile
FROM ruby:2.5
RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    node.js \
    yarn

# 作業ディレクトリに移動(無ければ自動で作成します)
WORKDIR /app
#build context内のGemfileとGemfile.lockをコピー
COPY Gemfile Gemfile.lock /app/
#Gemをインストール
RUN bundle install

Gemfileを編集

Gemfile
source 'https://rubygems.org'
gem 'rails', '~>5.2'

docker-compose.ymlを編集

docker-compose.yml
version: '3'
services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - 3000:3000
    depends_on:
      - db
    tty: true
    stdin_open: true
  db:
    image: mysql:5.7
    volumes:
      - db-volume:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
volumes:
  db-volume:

コンテナを起動する

$docker-compose -up -d

コンテナの中に入ってセットアップ

$docker-compose exec web bash
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0