0
2

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 3 years have passed since last update.

Railsでの新規appのdockerでの環境構築

Last updated at Posted at 2020-02-03

#dockerにての環境構築手順まとめ
忘れる前にまとめておきます
##環境構築の流れ

0 dockerfile gemfile gemfilelock docker-compose.ymlをセットする

docker-compose.ymlの一例

docker-compose.yml

version: '3'
services:
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/app
    ports:
      - 3000:3000
    depends_on:
      - db
    tty: true
    stdin_open: true
  db:
    image: mysql:5.7
    volumes:
      - db-volume:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: password
volumes:
  db-volume:

###1 新しいrailsprojectの作成

$ docker-compose run web rails new . --force --database=mysql

###2 database.ymlのセッティング
※DBファイルなのでインデントに注意
####database.ymlのpasswordとhostをdocker-compose.ymlでセットしたものに合わせる

database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  username: root
  password: password
  host: db

development:
       ~略~

###3 dockerfileからビルド

$ docker-compose build

###4 コンテナの起動

$ docker-compose up -d

###5 データベースの構築

$ docker-compose run web rails db:create

####コンテナの立ち上げしてURLにhhtp://ip:3000でrailsたちあがる
###ip 検索

$ docker-machine ip default

###コンテナOFF

$ docker-compose stop

##おまけ 
####dockerでERROR: Encountered errors while bringing up the project.というエラーが出た時に

$ docker stop $(docker ps -q)

$ docker-compose up

とやるとうまくいった。
参考 https://remonote.jp/docker-mac-rails-postgresql

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?