【发布时间】:2021-02-22 08:59:20
【问题描述】:
在启用了 ufw 的 ubuntu 18.04 上,我运行 docker 容器,它应该将 django 应用程序连接到本地安装的 Postgresql 服务器。
当 ufw 被禁用时,一切运行完美
docker-compose -f docker-compose.prod.yml run --rm app sh -c 'python manage.py createsuperuser'
但启用 ufw 我得到以下错误:
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Operation timed out
Is the server running on host "host.docker.internal" (172.17.0.1) and accepting
TCP/IP connections on port 5432?
我有以下 ufw 规则
$ sudo ufw status
Status: active
To Action From
-- ------ ----
Nginx Full ALLOW Anywhere
OpenSSH ALLOW Anywhere
20/tcp ALLOW Anywhere
21/tcp ALLOW Anywhere
990/tcp ALLOW Anywhere
40000:50000/tcp ALLOW Anywhere
Nginx Full (v6) ALLOW Anywhere (v6)
OpenSSH (v6) ALLOW Anywhere (v6)
20/tcp (v6) ALLOW Anywhere (v6)
21/tcp (v6) ALLOW Anywhere (v6)
990/tcp (v6) ALLOW Anywhere (v6)
40000:50000/tcp (v6) ALLOW Anywhere (v6)
如何正确配置ufw,让容器连接Postgres?
【问题讨论】:
标签: django postgresql docker ubuntu ufw