Bootstrap web_only container gets PG::Error for separated data container


(nx2zdk) #1

All of this setup is on the same host.

Note that: docker0 inet address is 172.17.42.1 and data container is running as:

CONTAINER ID        IMAGE                         COMMAND             CREATED             STATUS              PORTS                                                                  NAMES
8754aa7b07cf        local_discourse/data:latest   "/sbin/runit"       About an hour ago   Up About an hour    0.0.0.0:2221->22/tcp, 0.0.0.0:5432->5432/tcp, 0.0.0.0:6379->6379/tcp   data

When I try runinning this command:

psql -h 172.17.42.1 -p 5432 -U discourse discourse -W

and enter password for the password prompt, I get into postgres console without any error.

On bootstrap process, I run:

./launcher bootstrap web_only

And It failed with this error:

I, [2014-09-30T17:56:56.373972 #38]  INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
rake aborted!
PG::Error: could not connect to server: Connection refused
        Is the server running on host "172.17.42.1" and accepting
        TCP/IP connections on port 5432?

That looks like the app cannot connect to postgresql server on the data container (which is already bootstrapped and started and I was able to connect via psql)

my web_only.yml looks like this (excepts the credential, domain name and email):

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
  ## TODO: How many concurrent web requests are supported?
  ## With 2GB we recommend 3-4 workers, with 1GB only 2
  #UNICORN_WORKERS: 3

  ## TODO: configure connectivity to the databases
  DISCOURSE_DB_SOCKET: ''
  DISCOURSE_DB_USER: discourse
  DISCOURSE_DB_PASSWORD: mypassword
  DISCOURSE_DB_HOST: 172.17.42.1
  DISCOURSE_DB_NAME: discourse
  DISCOURSE_REDIS_HOST: 172.17.42.1
  ##
  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example 'user1@example.com,user2@example.com'
  DISCOURSE_DEVELOPER_EMAILS: 'MYEMAIL'
  ##
  ## TODO: The domain name this Discourse instance will respond to
  DISCOURSE_HOSTNAME: 'discuss.MYDOMAIN'
  ##
  ## TODO: The mailserver this Discourse instance will use
  DISCOURSE_SMTP_ADDRESS: smtp.mandrillapp.com         # (mandatory)
  DISCOURSE_SMTP_PORT: 587                        
  DISCOURSE_SMTP_USER_NAME: MYEMAIL
  DISCOURSE_SMTP_PASSWORD: APIKEY
  ##
  ## The CDN address for this Discourse instance (configured to pull)
  #DISCOURSE_CDN_URL: //discourse-cdn.example.com

volumes:
  - volume:
      host: /var/discourse/shared/web-only
      guest: /shared
  - volume:
      host: /var/discourse/shared/web-only/log/var-log
      guest: /var/log

## The docker manager plugin allows you to one-click upgrade Discouse
## http://discourse.example.com/admin/docker
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - mkdir -p plugins
          - git clone https://github.com/discourse/docker_manager.git

## 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 'MYPASSWORD')" 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;}'

and data.yml

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/sshd.template.yml"

expose:
  - "5432:5432"
  - "6379:6379"
  - "2221:22"

params:
  db_default_text_search_config: "pg_catalog.english"
  ## Set db_shared_buffers to 1/3 of the memory you wish to allocate to postgres
  ## on 1GB install set to 128MB on a 4GB instance you may raise to 1GB
  #db_shared_buffers: "256MB"

env:
  # ensure locale exists in container, you may need to install it
  LANG: en_US.UTF-8

volumes:
  - volume:
        host: /var/discourse/shared/data
        guest: /shared
  - volume:
        host: /var/discourse/shared/data/log/var-log
        guest: /var/log

# TODO: SOME_SECRET to a password for the discourse user
hooks:
  after_postgres:
    - exec:
        stdin: |
          alter user discourse with password 'MYPASSWORD';
        cmd: su - postgres -c 'psql discourse'

        raise_on_fail: false

Any idea what could cause this error or anything missing to config?


(Sam Saffron) #2

try launching a container and see if you can access it from there.

eg:

docker run -it --rm samsaffron/discourse
psql -h 172.17.42.1 -p 5432 -U discourse discourse -W

Maybe an issue internally networking containers?


(nx2zdk) #3

ah, exactly. it’s docker container internal network issue.

docker run -it --rm samsaffron/discourse /bin/bash
root@fb29d76fb090:/# psql -h 172.17.42.1 -p 5432 -U discourse discourse -W
Password for user discourse:
psql: could not connect to server: Connection refused
	Is the server running on host "172.17.42.1" and accepting
	TCP/IP connections on port 5432?

Well, how to config docker container so it can connect to other postgresql server container?


(Sam Saffron) #4

If it’s a single host you could share sockets, or as a workaround expose ports to host and use host ip


(nx2zdk) #5

Ok, thanks. I’ll figure out how to do that exactly.


(nx2zdk) #6

Is it possible to pass optional parameter to ./launcher bootstrap web_only
e.g. ./launcher bootstrap --link data:data web_only ?

So, it will link source and recipient containers like so:

root@olas-live:~# docker run --name web --link data:data -it --rm samsaffron/discourse /bin/bash
root@971e4e853b04:/# psql -h data -p 5432 -U discourse discourse -W
Password for user discourse:
psql (9.3.4, server 9.3.5)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.

discourse=>

Ps. I have looked at the launcher source code but not exactly sure if it’s possible.


(Sam Saffron) #7

no, but I am fine for a PR that adds this support.


(nx2zdk) #8

ok, I will send PR for the support.


(nx2zdk) #9

The pull request has just been sent :wink:


(nx2zdk) #10

Any feedback for the PR? Does it make any sense?


(Sam Saffron) #11

PR looks good, sorry about the delay, merged it in.


(nx2zdk) #12

Don’t worry, thanks for merging in.
Would it also need to put the usage on README? I think I forgot adding it there. If so, I’m ok to make another PR solely for that.


(Sam Saffron) #13

sure, please update the readme in an advanced section.


(nx2zdk) #14

Done!

I add the link there to Linking containers for a multiple container setup
I would add to howto category, but I wasn’t able to add ( may be no permission ). If you could edit that.

Thanks.