# How do I open the Rails console in Discourse Docker in production mode?

**URL:** https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970
**Category:** Self-hosting
**Tags:** hosting
**Created:** [6월 28, 2014, 9:37오후 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970 "2014-06-28T21:37:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![spocksplanet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spocksplanet/32/114462_2.png) [@spocksplanet](https://meta.discourse.org/u/spocksplanet)
#### Post date: [6월 28, 2014, 9:37오후 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970/1 "2014-06-28T21:37:25Z")

</div>

I have tried to use the following commands to get to the console, but I am encountering a lot of errors when I run the command. Here is the input:

```
  docker run -i -t local_discourse/app:latest bash
  cd /var/www/discourse/
  RAILS_ENV=production bundle exec rails c

```

And here is the shortened output:

```
  root@d19b0a20422c:/var/www/discourse# RAILS_ENV=production bundle exec rails c
  Rails Error: Unable to access log file. Please ensure that /var/www/discourse/log/production.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
  Error connecting to Redis on localhost:6379 (ECONNREFUSED) subscribe failed, reconnecting in 1 second. Call stack [
  Error connecting to Redis on localhost:6379 (ECONNREFUSED) subscribe failed, reconnecting in 1 second. Call stack [
  Error connecting to Redis on localhost:6379 (ECONNREFUSED) subscribe failed, reconnecting in 1 second. Call stack [
  /var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `initialize': could not connect to server: No such file or directory (PG::Error)
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

  root@d19b0a20422c:/var/www/discourse#

```

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [6월 28, 2014, 9:38오후 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970/2 "2014-06-28T21:38:17Z")

</div>

Run `rails c` instead - this will open the console as the correct user in the correct mode.

You can also do this with `rake` and `discourse` (for `/var/www/discourse/script/discourse`).

---

<div class="post-metadata">

### Author: ![spocksplanet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/spocksplanet/32/114462_2.png) [@spocksplanet](https://meta.discourse.org/u/spocksplanet)
#### Post date: [6월 28, 2014, 9:43오후 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970/3 "2014-06-28T21:43:58Z")

</div>

I didn’t know about the `discourse` command. That’s cool. But I still cannot get it to work. I get the same giant error complaining about the lack of the log file, and not being able to connect to the database server.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [6월 28, 2014, 11:19오후 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970/5 "2014-06-28T23:19:02Z")

</div>

You’re launching the container running a single command only: bash

That’s analogous to booting a VM in single user mode.

As Sam says, launch it normally and then ssh in.

---

<div class="post-metadata">

### Author: ![metakermit](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/metakermit/32/119609_2.png) [@metakermit](https://meta.discourse.org/u/metakermit)
#### Post date: [4월 4, 2018, 12:34오후 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970/6 "2018-04-04T12:34:35Z")

</div>

Just a correction:

```plaintext
cd /var/discourse/
./launcher enter app
rails c

```

---

<div class="post-metadata">

### Author: ![ahmed\_alamiry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ahmed_alamiry/32/198190_2.png) [@ahmed\_alamiry](https://meta.discourse.org/u/ahmed_alamiry)
#### Post date: [1월 30, 2019, 8:23오전 UTC](https://meta.discourse.org/t/how-do-i-open-the-rails-console-in-discourse-docker-in-production-mode/16970/7 "2019-01-30T08:23:45Z")

</div>

I added the bellow in app. yml, but it fails, how can I run rails c with out interacting I need to run it once. (I am using ansible to automate installation)

```
run:
  - exec: echo "Beginning of custom commands"
  # If you want to set the 'From' email address for your first registration, uncomment and change:
  # After getting the first signup email, re-comment the line. It only needs to run once.
  - exec: rails r "u = User.create!(username: '{{ discourse_developer_username }}', email: '{{ discourse_developer_emails }}', password: '{{ discourse_developer_password }}', admin: true)"

```
