Docker fails to start: psql: FATAL: the database system is starting up

I built the image successfully, and when I go to run it like so:

$ docker run -P -ti -v /var/lib/gitlab:/var/opt/gitlab -v /etc/gitlab:/etc/gitlab -v /var/log/gitlab:/var/log/gitlab --rm gitlab

It succeeds the first time, and subsequently crashes the second time with this message:

  * service[postgresql] action nothing (skipped due to action :nothing)
  * execute[create gitlab database user] action run
================================================================================
Error executing action `run` on resource 'execute[create gitlab database user]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '2'
---- Begin output of /opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c "CREATE USER gitlab" ----
STDOUT: 
STDERR: psql: FATAL:  the database system is starting up
---- End output of /opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c "CREATE USER gitlab" ----
Ran /opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c "CREATE USER gitlab" returned 2


Resource Declaration:
---------------------
# In /opt/gitlab/embedded/cookbooks/gitlab/recipes/postgresql.rb

160:   execute "create #{sql_user} database user" do
161:     command "#{bin_dir}/psql --port #{pg_port} -d template1 -c \"CREATE USER #{sql_user}\""
162:     user pg_user
163:     not_if { !pg_helper.is_running? || pg_helper.user_exists?(sql_user) }
164:   end
165: 



Compiled Resource:
------------------
# Declared in /opt/gitlab/embedded/cookbooks/gitlab/recipes/postgresql.rb:160:in `block in from_file'

execute("create gitlab database user") do
  action "run"
  retries 0
  retry_delay 2
  guard_interpreter :default
  command "/opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c \"CREATE USER gitlab\""
  backup 5
  returns 0
  user "gitlab-psql"
  cookbook_name :gitlab
  recipe_name "postgresql"
  not_if { #code block }
end




Running handlers:
[2014-12-14T14:14:17+00:00] ERROR: Running exception handlers
Running handlers complete

[2014-12-14T14:14:17+00:00] ERROR: Exception handlers complete
[2014-12-14T14:14:17+00:00] FATAL: Stacktrace dumped to /opt/gitlab/embedded/cookbooks/cache/chef-stacktrace.out
Chef Client failed. 52 resources updated in 7.505607606 seconds
[2014-12-14T14:14:17+00:00] ERROR: execute[create gitlab database user] (gitlab::postgresql line 160) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '2'
---- Begin output of /opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c "CREATE USER gitlab" ----
STDOUT: 
STDERR: psql: FATAL:  the database system is starting up
---- End output of /opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c "CREATE USER gitlab" ----
Ran /opt/gitlab/embedded/bin/psql --port 5432 -d template1 -c "CREATE USER gitlab" returned 2
[2014-12-14T14:14:17+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Assignee Loading
Time tracking Loading