Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?
@yuki-maru

Docker + Ruby on Rails 5 のメモ

More than 3 years have passed since last update.

Docker + Ruby on Rails 5 のメモ

Dockerfile
FROM ruby:2.3.1
ENV LANG C.UTF-8
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

ENV APP_HOME /myapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

ADD Gemfile* $APP_HOME/

RUN bundle install
docker-compose.yml
version: '2'
services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
Gemfile
source "https://rubygems.org"
gem 'rails', '~> 5.0.0'

$ touch Gemfile.lock で空のファイルを作成。

$ docker-compose build で Rails ビルド。
$ docker-compose run web rails new . --force --skip-bundle でデフォルトのアプリ作成。
↑ ここのwebdocker-compose.ymlservicesで定義しているweb

rails newで新たにGemfileが生成されるので$ docker-compose build で再度ビルド。

$ docker-compose upでアプリ起動。

ブラウザから 0.0.0.0:3000 にアクセスして動作確認。

【参考】 https://docs.docker.com/compose/rails/

11
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
11
Help us understand the problem. What is going on with this article?