I’m trying to deploy ghost with Docker. For that I deploy two container’s one for ghost app and one for my database.
On my server another container is running on port 3306 (default port for mysql database), so I changed the port to 3307 for my ghost database.
I also added the database__connection__port to port 3307 to matches the change.
But when I deploy it… I’ve got the folowing error:
[2024-03-17 22:47:20] WARN Ghost is shutting down
[2024-03-17 22:47:20] WARN Ghost has shut down
[2024-03-17 22:47:20] WARN Ghost was running for a few seconds
[2024-03-17 22:47:47] INFO Ghost is running in development...
[2024-03-17 22:47:47] INFO Listening on: :::2368
[2024-03-17 22:47:47] INFO Url configured as: https://ghost.domain/
[2024-03-17 22:47:47] INFO Ctrl+C to shut down
[2024-03-17 22:47:47] INFO Ghost server started in 0.431s
[2024-03-17 22:47:47] ERROR connect ECONNREFUSED 172.19.0.3:3307
connect ECONNREFUSED 172.19.0.3:3307
"Unknown database error"
Error ID:
500
Error Code:
ECONNREFUSED
----------------------------------------
Error: connect ECONNREFUSED 172.19.0.3:3307
at /var/lib/ghost/versions/5.80.3/node_modules/knex-migrator/lib/database.js:57:19
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
Here is my config (deployed with ansible that’s why the syntax is not like docker compose but it’s the same principle):
Of course my two containers are in the same network.
I don’t know why it’s not working here… I’ve tried many things to make it work but always got the same result.
NOTE: When I let the port to default (3306) for my ghost database and stop my other container that was already using the 3306 port everything work well…
Thanks in advance to anyone who can help me!
Have a nice day.
Try: docker ps -a to list containers and their ports.
Try: sudo netstat -atlpn to see all connections on the Docker bridge.
Try: docker port <container_name_or_id> on both containers.
I’m creating an Ansible role now to automate setting up Ghost with containers, perhaps you would be interested. Although, I’m using Podman and not Docker.
$ docker port ghost_db
3306/tcp -> 0.0.0.0:3307
$docker port ghost
no result
$ docker ps -a
67e8c8ae352e ghost:latest "docker-entrypoint.s…" 4 hours ago Up Less than a second 0.0.0.0:2368->2368/tcp ghost
5b5e61c5c8bf mysql:8.0-debian "docker-entrypoint.s…" 4 hours ago Up 4 hours 33060/tcp, 0.0.0.0:3307->3306/tcp ghost_db
The ghost container restarts in a loop due to database connection error.
I think the error comes from the container, has anyone managed to get ghost and the database working with a modified port (different that default 3306)?
Why not for your ansible code, it might help me ;)
So far you’ve shown how ports are mapped from containers to the host, but now how the containers can connect to each other.
Use commands like:
## See what's attached to the network you recreated
docker network inspect <network_name_or_id>
## See what network each container is attache dto.
docker container inspect <container_name_or_id>
To confirm how your containers are networked with each other.
Or you could enable host networking for the containers, where they could use port 3307
Any change made to the environnement variable “database__connection__port” made the whole thing broken… But everything is working when I use the default port 3306.
I think it’s a more likely to be a bug of the ghost container.
I think you should not do this port mapping, because both the host and the Ghost containers can access MySQL by IP address on the bridge networking you have created for it.
Use the -ip option with MySQL to assign it an IP address within the private network, like 172.19.33.06.
Update Ghost connection string to connect to 172.19.33.06.
The result should be that your main MySQL will be running on the host at port 3306 and your MySQL container will be running on this private IP at port 3306.
It’s not good security for containers to be able to access the host, which is why it’s better to run MySQL on a private IP that both the containers and the host can access than run on a custom port on the host that the containers are supposed to connect back to.