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


(Volkan Unsal) #1

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#

(Kane York) #2

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).


(Volkan Unsal) #3

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.


(Michael Brown) #5

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.


(Dražen Lučanin) #6

Just a correction:

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