28
33

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.

docker-composeでよく使うコマンド(Ruby on Rails)

Last updated at Posted at 2020-02-02

MySQLを使う場合

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

model作成

docker-compose run web bundle exec rails g model (モデル名) (カラム名)

バックグラウンドでコンテナ起動

docker-compose up -d

コンテナ再起動

docker-compose restart

Gemfile変更時(基本的には)

$ docker-compose build

DBへテストデータ投入

$ docker-compose exec web bundle exec rake db:seed

DBへテストデータを一から入れ直したい時
(テーブル削除、作成、マイグレーション)

$ docker-compose exec web bundle exec rake db:drop
$ docker-compose exec web bundle exec rake db:create
$ docker-compose exec web bundle exec rake db:migrate
$ docker-compose exec web bundle exec rake db:seed

dockerコンテナ、イメージ削除

$ docker rm $(docker ps -q -a)
$ docker rmi $(docker images -q)

補足: kaminari設定ファイル生成

$ docker-compose exec web bundle exec rails g kaminari:config

補足: kaminari(bootstrap4)ファイル生成(bootstrap4)

$ docker-compose exec web bundle exec rails g kaminari:views bootstrap4

補足: kaminariページネーションファイル生成

$ docker-compose exec web bundle exec rails g kaminari:config

Rspecを使う場合(Gemfileにはrspecの記述をする)

$ docker-compose run web bundle exec rails g rspec:install 
28
33
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
28
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?