# ECONNREFUSED when deploying Ghost via Docker

**URL:** <https://forum.ghost.org/t/econnrefused-when-deploying-ghost-via-docker/35108>\
**Category:** Installation\
**Created:** [December 29, 2022, 12:32pm UTC](https://forum.ghost.org/t/econnrefused-when-deploying-ghost-via-docker/35108 "2022-12-29T12:32:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexKalopsia](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/alexkalopsia/32/4161_2.png) [@AlexKalopsia](https://forum.ghost.org/u/AlexKalopsia)\
**Post date:** [December 29, 2022, 12:32pm UTC](https://forum.ghost.org/t/econnrefused-when-deploying-ghost-via-docker/35108/1 "2022-12-29T12:32:40Z")

</div>

Hi everyone, I am trying to deploy Ghost 5 via docker on my Synology NAS. The problem I am running into is that I keep getting an error that prevents Ghost from communicating with MySQL.

```auto
[2022-12-29 12:24:45] INFO Ghost is running in production...
[2022-12-29 12:24:45] INFO Your site is now available on http://localhost:2368/
[2022-12-29 12:24:45] INFO Ctrl+C to shut down
[2022-12-29 12:24:45] INFO Ghost server started in 21.608s
[2022-12-29 12:24:50] ERROR connect ECONNREFUSED 172.31.0.2:3306

connect ECONNREFUSED 172.31.0.2:3306

"Unknown database error"

Error ID:
    500

Error Code:
    ECONNREFUSED

----------------------------------------

Error: connect ECONNREFUSED 172.31.0.2:3306
    at /var/lib/ghost/versions/5.26.3/node_modules/knex-migrator/lib/database.js:57:19
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16)

[2022-12-29 12:24:50] WARN Ghost is shutting down
[2022-12-29 12:24:50] WARN Ghost has shut down
[2022-12-29 12:24:50] WARN Your site is now offline
[2022-12-29 12:24:50] WARN Ghost was running for a few seconds

```

My `docker-compose` looks like this

```auto
version: "3.7"
services: 

  ghost:
    container_name: ghost
    image: ghost:latest
    volumes:
      - ./ghost/content:/var/lib/ghost/content
    environment:
      - database__client=mysql
      - database __connection__ host=mysql
      - database __connection__ user=root
      - database __connection__ password=${MYSQL_PSW}
      - database __connection__ database=${MYSQL_DB}
    ports:
      - 2368:2368
    depends_on:
      - mysql
    restart: unless-stopped

  mysql:
    container_name: ghost-laughandgrowfat-db
    image: 'mysql:latest'
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_PSW}
    restart: unless-stopped

```

I honestly don’t know what to do anymore, I tried so many things and yet I can’t manage to deploy succesfully.

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![Alexg](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/alexg/32/28102_2.png) [@Alexg](https://forum.ghost.org/u/Alexg)\
**Post date:** [December 30, 2022, 6:58pm UTC](https://forum.ghost.org/t/econnrefused-when-deploying-ghost-via-docker/35108/2 "2022-12-30T18:58:17Z")

</div>

Hey @AlexKalopsia,

I think you’re missing some mysql environment variables namely (Need to add these under the mysql container environment section with your MYSQL\_ROOT\_PASSWORD environment variable):

```
  MYSQL_DATABASE: new_database
  MYSQL_USER: database_user
  MYSQL_PASSWORD: mysql_password

```

Let us know how you get on and if that works.

Cheers,

Alex.

---

<div class="post-metadata">

**Author:** ![RodoggA](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/rodogga/32/6259_2.png) [@RodoggA](https://forum.ghost.org/u/RodoggA)\
**Post date:** [June 7, 2025, 2:10pm UTC](https://forum.ghost.org/t/econnrefused-when-deploying-ghost-via-docker/35108/3 "2025-06-07T14:10:29Z")

</div>

Hey everyone — wanted to share a detailed breakdown of the troubleshooting steps I went through to get Ghost working with a MySQL-compatible database via Docker Compose. Hopefully this helps someone else hitting similar errors!

> ⚠ **Disclaimer:**  
> While this troubleshooting guide recommends switching to MariaDB to resolve certain connectivity issues, please note that **Ghost officially supports MySQL (versions 5.7 and above)** as the primary database.  
> MariaDB is not officially listed as a supported database in the Ghost documentation, but it is a highly compatible drop-in replacement for MySQL and works well in many real-world scenarios.  
> If you prefer strict adherence to officially supported configurations, it is recommended to use MySQL. However, if MariaDB fits your environment and resolves your issues, it is a practical alternative.

**Summary of Issues**  
While deploying Ghost using Docker Compose with a MySQL backend, I ran into repeated connection issues from Ghost to the DB. The issues encountered are listed below as well as the troubleshooting steps I took. Hopefully this can help others.

- `ECONNREFUSED` errors
- `caching_sha2_password` plugin errors (MariaDB client unable to connect to MySQL 8+)

### 🛠 Troubleshooting Steps:

1. **Error: `MYSQL_USER="root"` not allowed**

2. **Error: `connect ECONNREFUSED`**

```yaml
ghost:
    image: ghost:5-alpine
    container_name: ghost
    restart: always
    depends_on:
      - db
    ports:
      - 8080:8080
    environment:
      database__client: mysql
      database __connection__ host: db
      database __connection__ user: ghost
      database __connection__ password: ghost_password
      database __connection__ database: ghost
      url: http://ghost.domain.com:8080
    volumes:
      - ghost:/var/lib/ghost/content
    networks:
      - ghost

```

1. **Interactive Testing Inside Container:**  
I was able to perform test inside the container using the `docker exec -it containerName bash` command from the server, enableing me to login to the container.

2. **Final Decision: Switch to MariaDB**
