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 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>22/tcp,>5432/tcp,>6379/tcp   data

When I try runinning this command:

psql -h -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 "" 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/sshd.template.yml"
  - "templates/web.template.yml"

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

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

  LANG: en_US.UTF-8
  ## TODO: How many concurrent web requests are supported?
  ## With 2GB we recommend 3-4 workers, with 1GB only 2

  ## TODO: configure connectivity to the databases
  DISCOURSE_DB_USER: discourse
  DISCOURSE_DB_NAME: discourse
  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example ','
  ## TODO: The domain name this Discourse instance will respond to
  ## TODO: The mailserver this Discourse instance will use
  DISCOURSE_SMTP_ADDRESS:         # (mandatory)
  DISCOURSE_SMTP_PORT: 587                        
  ## The CDN address for this Discourse instance (configured to pull)

  - 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
    - exec:
        cd: $home/plugins
          - mkdir -p plugins
          - git clone

## Remember, this is YAML syntax - you can only have one block with a name
  - 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/postgres.template.yml"
  - "templates/redis.template.yml"
  - "templates/sshd.template.yml"

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

  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"

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

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


docker run -it --rm samsaffron/discourse
psql -h -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 -p 5432 -U discourse discourse -W
Password for user discourse:
psql: could not connect to server: Connection refused
	Is the server running on host "" 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.


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


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.