LoginSignup
15
8

More than 3 years have passed since last update.

【Rails】dockerでrailsコンソールを使う方法

Last updated at Posted at 2020-12-15

個人メモです。

dockerで起動しているアプリケーションのrails consoleにアクセスする方法。

dockerのコンテナ内でrails cを実行する。

rails consoleの起動

ターミナル
##入りたいコンテナ名を確認
docker ps

##コンテナに入る
docker exec -it コンテナ名 /bin/bash

##railsコンソールを開く
root@96913c74e902:/app# rails c

`Redis#exists(key)` will return an Integer by default in redis-rb 4.3. The option to explicitly disable this behaviour via `Redis.exists_returns_integer` will be removed in 5.0. You should use `exists?` instead.
Loading development environment (Rails 6.0.3.2)

irb(main):001:0>

ターミナルが、ローカル($) -> docker(root@96913c74e902:) -> rails(irb(main))の順に変わっていく。

irbはrailsの対話モード。
Interactive Rubyの略。


終了方法と注意点

終了するときはexitquit

※末尾の番号が0以外のときはctrl + cでクリアしてから

##末尾が0以外だと抜けられない(式の途中と見做されている)
irb(main):014:2> quit
irb(main):015:2> exit
irb(main):016:2> 

##ctrl + c でクリアしてからexit
irb(main):017:0> exit 


コマンドの実行例

1行の場合
irb(main):001:0> p "hello rails"
"hello rails"
=> "hello rails"


irb(main):002:0> 1+2
=> 3
複数行の場合
irb(main):015:0> for i in 1...11 do
irb(main):016:1*   print "#{i} "
irb(main):017:1> end
1 2 3 4 5 6 7 8 9 10 => 1...11
15
8
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
15
8