docker-composeでrailsの開発環境を作る





今日は眠いので一旦本質的なファイルだけ置いておきます

あとで解説します

Dockerfile

FROM starefossen/ruby-node

MAINTAINER yukito ohira

WORKDIR /comopet
ENV LANG=C.UTF-8 \
    TZ=Asia/Tokyo \
    ROOT_PATH=/comopet \
    BUNDLE_PATH=vendor/bundle \
    BUNDLE_JOBS=4

RUN gem update
RUN gem update bundler

CMD ["bash"]

docker-compose.yml

version: '3.3'
services:
  nginx:
    image: nginx
  redis:
    image: redis
  ap:
    build: .
    ports:
      - "3000:3000"
    stdin_open: true
    tty: true
    command: bash -c "rm -rf /comopet/tmp/pids/server.pid && (bundle check || bundle install) && bundle exec rails s -b '0.0.0.0'"
    volumes:
      - .:/comopet
    depends_on:
      - db
      - redis
    environment:
      RAILS_ENV: development
  webpack:
    build: .
    command: yarn watch
    volumes:
    - .:/comopet
  db:
    image: postgres
    volumes:
      - comopet-db-data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: comopet
      POSTGRES_PASSWORD: hogehoge
  adminer:
    image: adminer
    ports:
      - 9000:8080

volumes:
  comopet-db-data:
    driver: local
  comopet-test-db-data:
    driver: local
  gems:
    driver: local


database.yml

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: comopet
  password: hogehoge
  host: db

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  url: <%= ENV['DATABASE_URL'] %>
  timeout: 5000