Ghost docker container error

Hello guys, I’ve been trying to install Ghost for the past few days but whatever I do, I always run into the same issue, namely the mysql container seems to start up correctly, but the ghost container throws
chown: /var/lib/ghost/content/db/mysql.sock: No such file or directory

I have no idea why it says /ghost/content/db when my db is persisted in /ghost/db.

I even tried using the bitnami/ghost image, but that runs into different issues. My docker-compose looks like this

version: '3.1'

services:

  ghost:
    image: ghost:5.75-alpine
    restart: always
    ports:
      - 8005:2368
    depends_on:
      - db
    environment:
      database__client: mysql
      database__connection__host: db
      database__connection__user: mysql
      database__connection__password: some_root_pass
      database__connection__database: ghost
      url: https://my.cool.domain

      mail__transport: SMTP
      mail__options__host: smtp.gmail.com
      mail__options__port: 587
      mail__options__secure: false
      mail__options__auth__user: my_email
      mail__options__auth__pass: 'my_email_pass'
    volumes:
      - /srv/mounted_drive/ghost:/var/lib/ghost/content

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: some_root_pass
    volumes:
      - /srv/mounted_drive/ghost/db:/var/lib/mysql

volumes:
  ghost:
  db:

I’m very close to giving up, please help.

Hello & welcome to the Ghost forum!

In your Docker compose file, there were a few issues.

The one that led to the error message was the fact that you’re trying to put the database volume inside the Ghost content volume – not entirely sure why, but this causes issues.

I have separated the two volumes. Ghost has a ./content/ folder and the database has a ./db/ folder.

Changing that part made Ghost start up, but no database connection was possible. So, I had a look at the credentials you provided. In your Ghost environment, you specify a user “mysql” with password “some_root_pass”. However, you only set a root password in the mysql environment.

So, I took the liberty to create the database you specified, as well as the user and a password in the db-service.

Now, I added a health check that I am running on some production sites. The mysql container needs longer to start up (especially the first time you run it) than the Ghost container. This will cause the Ghost container to crash until the MySQL container is available.

The healthcheck periodically checks whether the database is available. I then added the health check to the depends_on property in your Ghost container, so it only starts once the database is available.

Here is the final docker-compose.yml that I managed to successfully start on my local machine:

version: '3.1'

services:

  ghost:
    image: ghost:5.75-alpine
    restart: always
    ports:
      - 8005:2368
    depends_on:
      db:
        condition: service_healthy
    environment:
      database__client: mysql
      database__connection__host: db
      database__connection__user: mysql
      database__connection__password: some_pass
      database__connection__database: ghost
      url: https://my.cool.domain

      mail__transport: SMTP
      mail__options__host: smtp.gmail.com
      mail__options__port: 587
      mail__options__secure: false
      mail__options__auth__user: my_email
      mail__options__auth__pass: 'my_email_pass'
    volumes:
      - /srv/mounted_drive/ghost/content:/var/lib/ghost/content

  db:
    image: mysql:8.0
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: some_root_pass
      MYSQL_DATABASE: ghost
      MYSQL_USER: mysql
      MYSQL_PASSWORD: some_pass
    volumes:
      - /srv/mounted_drive/ghost/db:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -u $$MYSQL_USER --password=$$MYSQL_PASSWORD && mysql -u $$MYSQL_USER --password=$$MYSQL_PASSWORD -e 'SHOW DATABASES LIKE \"$$MYSQL_DATABASE\";'"]
      interval: 30s
      timeout: 10s
      retries: 5

volumes:
  ghost:
  db:

Thank you for your fast reply. I have updated my docker-compose accordingly, but now when trying to deploy I’m getting

failed to deploy a stack: Container ghost-official-db-1 
Recreate Container ghost-official-db-1 
Recreated Container ghost-official-ghost-1 
Recreate Container ghost-official-ghost-1 
Recreated Container ghost-official-db-1 
Starting Container ghost-official-db-1 
Started Container ghost-official-db-1 
Waiting container for service "db" is unhealthy

Any idea why?

You might need to remove the content of the volumes and completely destroy the containers, then try again. When I cleared all data on my local machine and ran docker compose up -d everything worked.

I found the issue to be a missing space in the healthcheck test.

-u$$MYSQL_USER should be -u $$MYSQL_USER

My blog is now up, migrated from Wordpress. Thank you very much for your help!

1 Like

Good point! I edited it in my original post for anybody who stumbles upon this in the future :slight_smile: