博士后考试不会开始。(包括Django和Docker)
我知道 我明白了 有人能帮我找出哪里出了问题吗 当我这样做的时候博士后考试不会开始。(包括Django和Docker),django,postgresql,docker,Django,Postgresql,Docker,我知道 我明白了 有人能帮我找出哪里出了问题吗 当我这样做的时候 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:
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
psql -U postgres -h localhost
它很好用
虽然我需要启动postgres,让它在Docker和Django上运行
请帮忙
提前谢谢
编辑:
当我这样做的时候
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
psql -U postgres -h localhost
我明白了
$docker组合
正在启动asynchttpproxy\u postgres\u 1
正在启动asynchttpproxy\u web\u 1
附加到asynchttpproxy\u postgres\u 1、asynchttpproxy\u web\u 1
postgres_1|日志:数据库系统中断;最后一次被发现是在2017年-
05-01 21:27:43 UTC
postgres_1|日志:数据库系统未正确关闭;正在进行自动恢复
postgres_1|日志:0/150F720处的记录长度无效:需要24,得到0
postgres_1|日志:不需要重做
postgres_1|日志:现在已启用MultiXact成员环绕保护
postgres_1|日志:数据库系统已准备好接受连接
web_1 |正在执行系统检查。。。
网络1|
web_1 |系统检查未发现任何问题(0静音)。
web_1 |由启动的线程中存在未处理的异常
web_1 |回溯(最近一次呼叫最后一次):
web|1 |文件“/usr/local/lib/python3.6/site packages/django/db/backends/base/base.py”,第130行,确保连接
web|u 1 | self.connect()
web|1 |文件“/usr/local/lib/python3.6/site packages/django/db/backends/base/base.py”,第119行,在connect中
web_1 | self.connection=self.get_new_connection(连接参数)
web|1 |文件“/usr/local/lib/python3.6/site packages/django/db/backends/postgresql_psycopg2/base.py”,第176行,在get_new|连接中
web_1 |连接=数据库.connect(**连接参数)
web|1 |文件“/usr/local/lib/python3.6/site packages/psycopg2/_init__.py”,第164行,在connect中
网络连接=连接(dsn,连接工厂=连接工厂,异步=异步)
web_1 | psycopg2.OperationalError:无法连接到服务器:连接被拒绝
web|1是在主机“localhost”(127.0.0.1)上运行并接受
端口5432上的web_1| TCP/IP连接?
web_1 |无法连接到服务器:无法分配请求的地址
web|1是在主机“localhost”(::1)上运行并接受
端口5432上的web_1| TCP/IP连接?
这里实际上显示了两个问题:
第一,当您试图手动运行PostgreSQL时,您直接在主机操作系统中运行它,并且已经有一个副本在那里运行,占用端口5432
运行docker时的第二个问题是,Django设置被配置为指向localhost
上的数据库。当您在Docker外部运行时,这将起作用,PostgreSQL副本直接在主机操作系统中运行,但在Docker中不起作用,因为web应用程序和数据库服务器在单独的容器中运行
要解决第二个问题,您只需更新Django的设置以连接到主机
postgres
,因为这是您在docker compose.yml
中用于数据库容器的名称,这里实际上显示了两个问题:
第一,当您试图手动运行PostgreSQL时,您直接在主机操作系统中运行它,并且已经有一个副本在那里运行,占用端口5432
运行docker时的第二个问题是,Django设置被配置为指向localhost
上的数据库。当您在Docker外部运行时,这将起作用,PostgreSQL副本直接在主机操作系统中运行,但在Docker中不起作用,因为web应用程序和数据库服务器在单独的容器中运行
要解决第二个问题,只需更新Django的设置即可连接到主机
postgres
,由于这是您在docker compose.yml
中用于数据库容器的名称,您的问题是在启动django的同时在docker compose上启动postgres
,因此,没有足够的时间进行数据库设置,正如您在端口5432上的连接TCP/IP连接中看到的错误一样?
。我已经解决了在docker-compose.yml上运行bash命令并创建wait-bd.sh bash脚本的问题
wait-bd.sh
$ docker-compose up
Starting asynchttpproxy_postgres_1
Starting asynchttpproxy_web_1
Attaching to asynchttpproxy_postgres_1, asynchttpproxy_web_1
postgres_1 | LOG: database system was interrupted; last known up at 2017-
05-01 21:27:43 UTC
postgres_1 | LOG: database system was not properly shut down; automatic recovery in progress
postgres_1 | LOG: invalid record length at 0/150F720: wanted 24, got 0
postgres_1 | LOG: redo is not required
postgres_1 | LOG: MultiXact member wraparound protections are now enabled
postgres_1 | LOG: database system is ready to accept connections
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f51f88bef28>
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 119, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 164, in connect
web_1 | conn = _connect(dsn, connection_factory=connection_factory, async=async)
web_1 | psycopg2.OperationalError: could not connect to server: Connection refused
web_1 | Is the server running on host "localhost" (127.0.0.1) and accepting
web_1 | TCP/IP connections on port 5432?
web_1 | could not connect to server: Cannot assign requested address
web_1 | Is the server running on host "localhost" (::1) and accepting
web_1 | 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安装容器。您的问题是在启动django的同时在docker compose上启动
postgres
,因此没有足够的时间进行数据库设置,正如您在端口5432上的连接TCP/IP连接中看到的错误一样?
。我已经解决了在docker-compose.yml上运行bash命令并创建wait-bd.sh bash脚本的问题
wait-bd.sh
$ docker-compose up
Starting asynchttpproxy_postgres_1
Starting asynchttpproxy_web_1
Attaching to asynchttpproxy_postgres_1, asynchttpproxy_web_1
postgres_1 | LOG: database system was interrupted; last known up at 2017-
05-01 21:27:43 UTC
postgres_1 | LOG: database system was not properly shut down; automatic recovery in progress
postgres_1 | LOG: invalid record length at 0/150F720: wanted 24, got 0
postgres_1 | LOG: redo is not required
postgres_1 | LOG: MultiXact member wraparound protections are now enabled
postgres_1 | LOG: database system is ready to accept connections
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 | Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f51f88bef28>
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 130, in ensure_connection
web_1 | self.connect()
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 119, in connect
web_1 | self.connection = self.get_new_connection(conn_params)
web_1 | File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 176, in get_new_connection
web_1 | connection = Database.connect(**conn_params)
web_1 | File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 164, in connect
web_1 | conn = _connect(dsn, connection_factory=connection_factory, async=async)
web_1 | psycopg2.OperationalError: could not connect to server: Connection refused
web_1 | Is the server running on host "localhost" (127.0.0.1) and accepting
web_1 | TCP/IP connections on port 5432?
web_1 | could not connect to server: Cannot assign requested address
web_1 | Is the server running on host "localhost" (::1) and accepting
web_1 | 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安装容器。听起来您已经有一个postgresql实例正在运行,因此您实际上不需要手动启动它。Joey,不,当我进行docker compose时,我会在编辑操作中得到回溯,这是另一个问题。您告诉Django连接到
localhost
,但您应该在单独的Docker容器上运行PostgreSQL。因此,您应该告诉Django连接到postgres
的主机名。非常感谢您的提示,没问题!我可能应该把它转换成一个答案…听起来你已经有一个postgresql实例在运行,所以你实际上不需要手动启动它。Joey,不,当我做docker compose时,我在编辑OpgreSQL时得到了回溯,这是另一个问题。你是