Or you can do this in one line, as follows:
docker exec -it app rails c
This is how I generally run the rails console when I have a quick query to do or to check some object, etc.
To make things easier, I have the following alias set up on my system (except the name of app is different for us):
alias railsc='docker exec -it app rails c'
In this manner, we can easily enter the rails console by typing railsc on the command line outside the container.
ubuntu:/home/neo# railsc
[1] pry(main)> User.count
=> 139160
[2] pry(main)> Topic.count
=> 380629
[3] pry(main)> Post.count
=> 1034861
[4] pry(main)> SiteSetting.count
=> 157
[5] pry(main)> SiteSetting.force_https
=> true
Don’t forget to change the name to match your container in your alias setup.
HTH.