2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails チュートリアルの要件を満たす最低限のdocker

Last updated at Posted at 2019-06-23

概要

https://docs.docker.com/compose/rails/
上記サイトのdocker設定にRailsチュートリアルで必要な追加項目をメモします。
※Railsチュートリアルhttps://railstutorial.jp/chapters/account_activation?version=5.1

##追加項目
1 postgresのパスワード

docker-compose.yml
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres

2 チュートリアル第10章docker-compose上のRailsでデバッグ(debugger)用

docker-compose.yml
  web:
    stdin_open: true
    tty: true

※デバッグ方法
$ docker attach コンテナ名で待ち受け

3 チュートリアル第13章のImageMagicインストール

Dockerfile
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client imagemagick

修正後のファイル

docker-compose.yml
version: '3'
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - '5433:5432'
  web:
    stdin_open: true
    tty: true
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db
Dockerfile
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client imagemagick
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?