I am using dokploy to make deployments using docker compose and traefik (reverse proxy) on my remote server instance. If I use the default docker-compose.yml
with the url http://localhost:8080
then it deploys fine but as soon as I change my url to https://blog.mydomain.com
then it give me database connection errors.
The error is:
[2024-11-26 11:25:29] INFO Ghost is running in production...
[2024-11-26 11:25:29] INFO Your site is now available on https://blog.mydomain.com/
[2024-11-26 11:25:29] INFO Ctrl+C to shut down
[2024-11-26 11:25:29] INFO Ghost server started in 1.867s
[2024-11-26 11:25:29] ERROR connect ECONNREFUSED 10.0.1.57:3306
connect ECONNREFUSED 10.0.1.57:3306
"Unknown database error"
Error ID:
500
Error Code:
ECONNREFUSED
----------------------------------------
Error: connect ECONNREFUSED 10.0.1.57:3306
at /var/lib/ghost/versions/5.101.1/node_modules/knex-migrator/lib/database.js:57:19
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
[2024-11-26 11:25:29] WARN Ghost is shutting down
[2024-11-26 11:25:29] WARN Ghost has shut down
[2024-11-26 11:25:29] WARN Your site is now offline
[2024-11-26 11:25:29] WARN Ghost was running for a few seconds
My docker-compose.yml
generated by dokploy looks like:
name: ghost-live-3
services:
ghost:
image: ghost:5-alpine
container_name: ghost_serv_live_c
restart: always
ports:
- '8080:2368'
environment:
database__client: mysql
database__connection__host: db
database__connection__user: root
database__connection__password: example
database__connection__database: ghost
url: https://blog.mydomain.com
volumes:
- ghost:/var/lib/ghost/content
depends_on:
- db
labels:
- traefik.enable=true
- traefik.http.routers.ghostlive-5-c-b88beb-39-web.rule=Host(`blog.mydomain.com`)
- traefik.http.routers.ghostlive-5-c-b88beb-39-web.entrypoints=web
- traefik.http.services.ghostlive-5-c-b88beb-39-web.loadbalancer.server.port=8080
- traefik.http.routers.ghostlive-5-c-b88beb-39-web.service=ghostlive-5-c-b88beb-39-web
- traefik.http.routers.ghostlive-5-c-b88beb-39-web.middlewares=redirect-to-https@file
- traefik.http.routers.ghostlive-5-c-b88beb-39-websecure.rule=Host(`blog.mydomain.com`)
- traefik.http.routers.ghostlive-5-c-b88beb-39-websecure.entrypoints=websecure
- traefik.http.services.ghostlive-5-c-b88beb-39-websecure.loadbalancer.server.port=8080
- traefik.http.routers.ghostlive-5-c-b88beb-39-websecure.service=ghostlive-5-c-b88beb-39-websecure
- traefik.http.routers.ghostlive-5-c-b88beb-39-websecure.tls.certresolver=letsencrypt
networks:
- dokploy-network
db:
image: mysql:8.0
container_name: ghost_db_live_c
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- db:/var/lib/mysql
volumes:
ghost: null
db: null
networks:
dokploy-network:
external: true
Do I expose db port 3306 or something. Any suggestions?
[UPDATE]
I made a few changes and added a new db user (instead of root user):
ghost:
image: ghost:5
...
networks:
- dokploy-network
environment:
database__connection__user: ghostuser
database__connection__password: ghostpass
database__connection__database: ghost
...
db:
...
networks:
- dokploy-network
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: ghost
MYSQL_USER: ghostuser
MYSQL_PASSWORD: ghostpass
...
Now I am getting 2 different errors:
Error 1:
[2024-11-28 17:39:24] ERROR connect ECONNREFUSED 10.0.1.57:3306
connect ECONNREFUSED 10.0.1.57:3306
Error ID:
b5a29d70-adaf-11ef-8b2a-0199df7a117c
Error Code:
ECONNREFUSED
----------------------------------------
Error: connect ECONNREFUSED 10.0.1.57:3306
at bootGhost (/var/lib/ghost/versions/5.101.1/core/boot.js:640:32)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
Error 2:
[2024-11-28 17:39:28] ERROR Unhandled rejection: connect ECONNREFUSED 10.0.1.108:3306
connect ECONNREFUSED 10.0.1.108:3306
Error Code:
ECONNREFUSED
----------------------------------------
Error: connect ECONNREFUSED 10.0.1.108:3306
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
On inspecting:
$ docker inspect ghost_db_live_c | grep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "",
"IPAddress": "10.0.1.113",
Why is ghost_db_live_c
container acccessible on IP addr: “10.0.1.113” but the ghost_serv_live_c
container trying to access the db container on the IP addrs: “10.0.1.57” and “10.0.1.108”?