Docker Discourse multisite 502 bad gateway, after bootstrapping both app and data container


(Shayden Martin) #1

After bootstrapping both containers, I am getting a 502 Bad gateway error, and after entering into the app container and running sudo -E -u discourse bundle exec rake multisite:migrate --trace manually. It appears the app container is not communicating with the data container correctly. I can successfully ping the data container from the app container. I have pasted the error output from multisite:migrate below:

root@localhost-web_ms:/var/www/discourse# sudo -E -u discourse bundle exec rake multisite:migrate --trace
** Invoke multisite:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
Errno::EHOSTUNREACH: No route to host
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/connection/hiredis.rb:16:in `connect'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/connection/hiredis.rb:16:in `connect'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:304:in `establish_connection'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:85:in `block in connect'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:266:in `with_reconnect'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:84:in `connect'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:326:in `ensure_connected'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:197:in `block in process'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:279:in `logging'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:196:in `process'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:167:in `call_pipelined'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:139:in `block in call_pipeline'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:266:in `with_reconnect'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis/client.rb:137:in `call_pipeline'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis.rb:2115:in `block in multi'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis.rb:37:in `block in synchronize'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis.rb:37:in `synchronize'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/redis-3.1.0/lib/redis.rb:2107:in `multi'
/var/www/discourse/lib/discourse_redis.rb:40:in `method_missing'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/logster-0.1.6/lib/logster/redis_store.rb:17:in `save'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/logster-0.1.6/lib/logster/base_store.rb:70:in `report'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/logster-0.1.6/lib/logster/logger.rb:47:in `add'
/usr/local/lib/ruby/2.0.0/logger.rb:445:in `warn'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/behaviors.rb:29:in `block in <class:Deprecation>'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/reporting.rb:19:in `call'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/reporting.rb:19:in `block (2 levels) in warn'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/reporting.rb:19:in `each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/reporting.rb:19:in `block in warn'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/reporting.rb:18:in `tap'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/reporting.rb:18:in `warn'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/deprecation/instance_delegator.rb:19:in `warn'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:238:in `resolve_string_connection'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:226:in `resolve_connection'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:152:in `resolve'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:182:in `spec'
/var/www/discourse/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb:134:in `block in load_settings!'
/var/www/discourse/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb:133:in `each'
/var/www/discourse/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb:133:in `map'
/var/www/discourse/vendor/gems/rails_multisite/lib/rails_multisite/connection_management.rb:133:in `load_settings!'
/var/www/discourse/vendor/gems/rails_multisite/lib/rails_multisite/railtie.rb:11:in `block in <class:Railtie>'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `instance_exec'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:30:in `run'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/local/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
/usr/local/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
/usr/local/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
/usr/local/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
/usr/local/lib/ruby/2.0.0/tsort.rb:180:in `each'
/usr/local/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
/usr/local/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/initializable.rb:54:in `run_initializers'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:300:in `initialize!'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `public_send'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `method_missing'
/var/www/discourse/config/environment.rb:5:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:276:in `require_environment!'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/railties-4.1.8/lib/rails/application.rb:389:in `block in run_tasks_blocks'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:240:in `call'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:240:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:235:in `each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:235:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:201:in `block in invoke_prerequisites'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:199:in `each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:199:in `invoke_prerequisites'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:178:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/task.rb:165:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:156:in `invoke_task'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:112:in `block (2 levels) in top_level'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:112:in `each'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:112:in `block in top_level'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:121:in `run_with_threads'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:106:in `top_level'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:84:in `block in run'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:182:in `standard_exception_handling'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/lib/rake/application.rb:79:in `run'
/var/www/discourse/vendor/bundle/ruby/2.0.0/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/var/www/discourse/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Tasks: TOP => multisite:migrate => environment

Any help on this is really appreciated.


502 Bad Gateway after failed upgrade
(Sam Saffron) #2

your redis ip address in the data container is not accessible the web container.


(Shayden Martin) #3

@sam But it’s the same as the data container and I can ping it successfully.

In any case, I rebuilt both containers and I’m no longer getting the 502, however the multisite configuration doesn’t appear to have worked either. Accessing the app form either domain directs me to the primary discourse site. I have posted my web container yml file below:

templates:
  - "templates/sshd.template.yml"
  - "templates/web.template.yml"

expose:
  - "80:80"
  - "2222:22"

params:
  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed

env:
  LANG: en_US.UTF-8

  UNICORN_WORKERS: 3

  DISCOURSE_DB_SOCKET: '5432'
  DISCOURSE_DB_USER: discourse
  DISCOURSE_DB_PASSWORD: mypass
  DISCOURSE_DB_HOST: data_ip
  DISCOURSE_REDIS_HOST: data_ip (also redis host)

  DISCOURSE_DEVELOPER_EMAILS: 'developer@mydomain.com'
  DISCOURSE_HOSTNAME: 'ourdomain1'

  DISCOURSE_SMTP_ADDRESS: mysmtphost
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: mysmtpuser
  DISCOURSE_SMTP_PASSWORD: mysmtppass

  ## The CDN address for this Discourse instance (configured to pull)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

  #CORS Settings, to enable ajax with json endpoints
  DISCOURSE_ENABLE_CORS: true
  DISCOURSE_CORS_ORIGIN: '*'

volumes:
  - volume:
      host: /var/docker/shared/web
      guest: /shared
  - volume:
      host: /var/docker/shared/web/log/var-log
      guest: /var/log

## The docker manager plugin allows you to one-click upgrade Discouse
## http://discourse.example.com/admin/docker
hooks:
  before_bundle_exex:
    - exec:
        cd: /var/www/discourse/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git
    - file:
        path: /var/www/discourse/config/multisite.yml
        contents: |
          fucsia:
            adapter: postgresql
            host: data_ip
            username: discourse
            password: mypass
            database: b_discourse
            pool: 25
            timeout: 5000
            db_id: 2
            host_names:
              - mydomain2

  after_bundle_exec:
    - exec:
        cd: /var/www/discourse
        cmd:
          - sudo -E -u discourse bundle exec rake multisite:migrate

## Remember, this is YAML syntax - you can only have one block with a name
run:
  - exec: echo "Beginning of custom commands"

  ## If you want to configure password login for root, uncomment and change:
  #- exec: apt-get -y install whois # for mkpasswd
  ## Use only one of the following lines:
  #- exec: /usr/sbin/usermod -p 'PASSWORD_HASH' root
  #- exec: /usr/sbin/usermod -p "$(mkpasswd -m sha-256 'RAW_PASSWORD')" root

  ## If you want to authorized additional users, uncomment and change:
  #- exec: ssh-import-id username
  #- exec: ssh-import-id anotherusername

  - exec: echo "End of custom commands"
  - exec: awk -F\# '{print $1;}' ~/.ssh/authorized_keys | awk 'BEGIN { print "Authorized SSH keys for this container:"; } NF>=2 {print $NF;}'

(Sam Saffron) #4

looks like a typo to me


(Shayden Martin) #5

Uhh, so it is. Thanks for your help!


(Daniel Lynch) #6

This error has been hell for me too. I was doing bootstrap instead of rebuild, so it wasn’t paying attention to my edits in data.yml and web_only.yml.

Also I did a little self-torture with firewall rules. I’ve settled on making INPUT default deny, and added these two lines into /etc/ufw/after.rules:

-I INPUT 3 -p tcp -s [MY IP] --dport 22 -j ACCEPT
-I INPUT 3 -p tcp -s 172.17.0.0/16 -j ACCEPT