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.
 pry(main)> User.count
 pry(main)> Topic.count
 pry(main)> Post.count
 pry(main)> SiteSetting.count
 pry(main)> SiteSetting.force_https
Don’t forget to change the name to match your container in your alias setup.