27
11

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.

docker-composeでmysql+redis+sidekiqなrails環境を作る

Last updated at Posted at 2017-03-26
  • RAILS_ROOT/Gemfile
# これ追加
gem 'sidekiq'
gem 'sinatra', require: false
gem 'redis'
gem 'redis-namespace'
  • RAILS_ROOT/config/routes.rb
Rails.application.routes.draw do
  # 2行追加
  require 'sidekiq/web'
  mount Sidekiq::Web => '/sidekiq'

  ...
end
  • RAILS_ROOT/config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
  config.redis = { url: 'redis://redis:6379', namespace: "sidekiq" }
end

Sidekiq.configure_client do |config|
  config.redis = { url: 'redis://redis:6379', namespace: "sidekiq" }
end
  • RAILS_ROOT/config/database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: password # ここ修正
  host: db # ここ修正
  • RAILS_ROOT/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
RUN gem install bundler
ENV app /app
RUN mkdir $app
WORKDIR $app
ADD Gemfile* $app/
ENV BUNDLE_GEMFILE=$app/Gemfile \
  BUNDLE_JOBS=2 \
  BUNDLE_PATH=/bundle
ADD . $app
  • RAILS_ROOT/docekr-compose.yml
version: '2'
services:
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
    volumes:
      - db-data:/var/lib/mysql
    ports:
      - "3306:3306"
  redis:
    image: redis
  app:
    build: .
    volumes:
      - bundle:/bundle
  web:
    extends:
      service: app
    command: /bin/sh -c "rm -f /app/tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/app
    ports:
      - "3000:3000"
    links:
      - db
      - redis
  worker:
    extends:
      service: app
    command: bundle exec sidekiq
    volumes:
      - .:/app
    links:
      - db
      - redis
volumes:
  db-data:
    driver: local
  bundle:
    driver: local

:octocat: https://github.com/t-taira/docker-compose-rails

27
11
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
27
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?