postgres没有开始。 (涉及Django和Docker)

时间:2017-05-01 22:19:51

标签: django postgresql docker

我做

it 'should use this form' do

  assert page.has_content?('#target_form')
  within '#target_form' do
    # fill in the form and apply payment
  end

  # it will throw errors here "can't find css..." 
  # the text/element won't even have loaded yet
  # by the time the test is run
  assert_equal '24', find_qa('price').text
end

我得到了

postgres -D /path/to/data

有人可以帮我弄清楚出了什么问题吗?

当我这样做时

2017-05-01 16:53:36 CDT LOG:  could not bind IPv6 socket: No error
2017-05-01 16:53:36 CDT HINT:  Is another postmaster already running on port 
5432? If not, wait a few seconds and retry.
2017-05-01 16:53:36 CDT LOG:  could not bind IPv4 socket: No error
2017-05-01 16:53:36 CDT HINT:  Is another postmaster already running on port 
5432? If not, wait a few seconds and retry.
2017-05-01 16:53:36 CDT WARNING:  could not create listen socket for "*"
2017-05-01 16:53:36 CDT FATAL:  could not create any TCP/IP sockets

它运作得很好。

虽然我需要启动postgres才能让它在Docker和Django上运行

请帮忙

提前致谢

编辑:

当我这样做时

psql -U postgres -h localhost

我得到了

docker-compose up 

2 个答案:

答案 0 :(得分:0)

这里显示实际上有两个问题:

首先,当您尝试手动运行PostgreSQL时,您是直接在主机操作系统中运行它,并且已经有一个副本在那里运行,占用了端口5432.

当您运行docker时,第二个问题是您的Django设置被配置为指向localhost上的数据库。当你在Docker之外运行时,这将起作用,PostgreSQL的副本直接在你的主机操作系统中运行,但在Docker中不起作用,因为web应用程序和数据库服务器在不同的容器中运行。

要解决第二个问题,您只需更新Django的设置即可连接到主机postgres,因为这是您在docker-compose.yml中用于数据库容器的名称。

答案 1 :(得分:0)

您的问题是在启动django的同时在docker compose上启动df['Activity_2'] = pd.np.where(df.Activity.str.contains("email"), "email", pd.np.where(df.Activity.str.contains("conference"), "conference", pd.np.where(df.Activity.str.contains("call"), "call", "task"))) df # Activity Activity_2 #0 email personA email #1 attend conference conference #2 send email email #3 call Sam call #4 random text task #5 random text task #6 lwantto call call 的时间,因此没有足够的时间进行数据库设置,因为您在连接错误中可以看到postgres 。我已经解决了在docker-compose.yml上运行bash命令并创建wait-bd.sh bash脚本的问题。

wait-bd.sh

TCP/IP connections on port 5432?

并在docker-compose.yml中在django容器中添加tag命令:

#!/bin/bash
  while true; do
    COUNT_PG=`psql postgresql://username:password@localhost:5432/name_db -c '\l \q' | grep "name_db" | wc -l`
    if ! [ "$COUNT_PG" -eq "0" ]; then
       break
    fi
       echo "Waiting Database Setup"
       sleep 10
  done

此脚本将等待您进行数据库设置,因此将运行django安装容器。