Help us understand the problem. What is going on with this article?

【Docker】Railsとmysqlをcomposeで動かすテンプレート

More than 3 years have passed since last update.

【Docker】Railsとmysqlをcomposeで動かすテンプレート

他テンプレート

やりたいこと

  • mysql と rails それぞれのコンテナーをdocker-composeがオーケストレーションして管理してくれるようにする

背景

  • 2年ほど前からdockerでサービスを動かしてきて、テンプレートシリーズを作りたいと思ってた

前提条件

  • 任意のgitリポジトリにrailsプロジェクトがある

使いどころ

  • ローカルのお試し開発環境で試すもよし
  • 本番でも有効なのかなと

試してみる

docker-compose.yml

  • いい感じに書き換える
  • もし、公式イメージをデフォのまま使いたいなら、imageを公式にしてpasswordとか設定すればいい
  • データの永続化はvolume-driverをコメントイン
#docker-compose.yml

app:
#  image: my-rails
  build: rails/
  environment:
    RAILS_ENV: development
  ports:
    - '3000:3000'
  volumes:
    - .:/usr/src/project_name
#  volume_driver: convoy-gluster
  command:
    - bash
    - -c
    - RAILS_ENV=development bundle exec rails s -p 3000 -b '0.0.0.0'
  links:
    - db:db
db:
#  image: mysql
  build: mysql/
#  stdin_open: true
#  volumes_from:
#    - data-mysql
  ports:
    - "3306:3306"
  environment:
#    MYSQL_ALLOW_EMPTY_PASSWORD: 'true'
#    MYSQL_ROOT_PASSWORD: password
#    MYSQL_DATABASE: test_db
#    MYSQL_USER: user
  • docker-compose up

その他追加事項

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
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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