擅长:python、mysql、java
<p>根据psycopg2的<a href="http://initd.org/psycopg/docs/module.html?highlight=operationalerror#psycopg2.connect" rel="nofollow noreferrer">documentation</a>。如果主机值为空,那么默认情况下它将查找Postgres的Unix套接字文件。在</p>
<p>在您的错误消息中,提到它正在查找<code>tmp</code>目录下的套接字文件(<strong>.s.PGSQL.5432</strong>)。在</p>
<p>如果您将<code>postgres</code>作为单独的容器运行,那么您可以在容器中的<code>/var/run/postgresql</code>目录下找到这个套接字文件。在</p>
<p>您可以将此文件夹装载到主机上,如下所示:</p>
<pre><code>docker run -e POSTGRES_PASSWORD=mysecretpassword -v /home/username/socket_dir:/var/run/postgresql -d postgres
</code></pre>
<p>然后可以更新<strong>数据库</strong>对象,如下所示:</p>
^{pr2}$
<p>现在应该建立联系了。在</p>