嗨,我正在努力配置Docker compose,以便在Debian 11上使用外部postgres数据库。容器似乎没有正确解析host.docker.internal。我第一次运行容器时,它工作正常,因为我使用的IP 172.17.0.1作为数据库,容器像往常一样在www.example.com上启动172.17.0.4,但每次我运行docker-compose时,它都会增加IP(172.18.0.4 172.19.0.4... 172.28.0.4)。
我尝试过的解决方案是:
- make host.docker.internal工作
- 找到一种方法,将合理的容器IP地址强制为172.17.0.4,并将172.17.0.1用于数据库。
- 使主机模式与localhost工作,但这不是最安全的一个
这是日志
Loading plausible..
Starting dependencies..
Starting repos..
Running migrations for Elixir.Plausible.Repo
06:57:08.578 [error] Postgrex.Protocol (#PID<0.164.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (host.docker.internal:5432): connection refused - :econnrefused
06:57:08.578 [error] Postgrex.Protocol (#PID<0.163.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (host.docker.internal:5432): connection refused - :econnrefused
06:57:09.988 [error] Postgrex.Protocol (#PID<0.163.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (host.docker.internal:5432): connection refused - :econnrefused
06:57:10.343 [error] Postgrex.Protocol (#PID<0.164.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (host.docker.internal:5432): connection refused - :econnrefused
06:57:11.505 [error] Could not create schema migrations table. This error usually happens due to the following:
* The database does not exist
* The "schema_migrations" table, which Ecto uses for managing
migrations, was defined by another library
* There is a deadlock while migrating (such as using concurrent
indexes with a migration_lock)
docker-compose.yml
version: "3.3"
#networks:
# lan_access:
# driver: bridge
services:
mail:
image: bytemark/smtp
restart: always
# plausible_db:
# supported versions are 12, 13, and 14
# image: postgres:14-alpine
# restart: always
# volumes:
# - db-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_PASSWORD=postgres
plausible_events_db:
image: clickhouse/clickhouse-server:23.3.7.5-alpine
restart: always
volumes:
- event-data:/var/lib/clickhouse
- ./clickhouse/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
- ./clickhouse/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
ulimits:
nofile:
soft: 262144
hard: 262144
plausible:
image: plausible/analytics:v2.0
restart: always
command: sh -c "sleep 10 && /entrypoint.sh db migrate && /entrypoint.sh run"
#command: sh -c "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run"
depends_on:
# - plausible_db
- plausible_events_db
# networks:
# - lan_access
# - default
# network_mode: bridge
# network_mode: host
ports:
- 8001:8000
env_file:
- plausible-conf.env
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
# db-data:
# driver: local
event-data:
driver: local
下面是可扩展的-conf.env
BASE_URL=https://analytics.example.com
SECRET_KEY_BASE=SECRET
DATABASE_URL=postgres://plausible:[email protected]:5432/plausible_db
#DATABASE_URL=postgres://plausible:[email protected]::5432/plausible_db
#DATABASE_URL=postgres://plausible:[email protected]:5432/plausible_db
MAILER_NAME=plausible
SMTP_HOST_ADDR=localhost
SMTP_HOST_PORT=25
你知道我的配置有什么问题吗?
1条答案
按热度按时间l2osamch1#
请看原文页面和代码:
运行时间:
docker-compose.yaml(我使用的):
可扩展的conf.env(我使用的):
当您使用DB设置时,plausible/analytics:v2.0无法正常运行。那就把它拿走
运行容器:
浏览器(http://localhost:8080),工作方式:
密码:
如果你想调试它,在运行docker-compose up -d后,运行docker container ls -a获取plausible/analytics:v2.0的容器id(例如:a14 d4 b63 ea 97),然后运行docker logs a14查看错误/logs。
运行“compose up”后,40秒后,如果似是而非/analytics:v2.0一次又一次地重新启动,则其上存在问题,并使用“docker logs”命令查看。
连接到另一个Postgresql容器:(此部分添加在注解后)
创建一个新的网桥网络,其中:
添加到docker-compose.yml文件:
plausible-conf.env:
通过此配置,plausible/analytics:v2.0可以通过docker网络连接Postgresql容器。
运行后,请看一下plausible/analytics:v2.0 container,里面有docker logs。
数据库连接完成(因为我在PostgreSQL容器上创建了plausible_db,并且没有数据库连接错误),但数据库上存在迁移问题。我认为这与Docker网络或DB连接无关。这是DB迁移问题。