Skip to content

Instantly share code, notes, and snippets.

@agc93
Created August 28, 2017 01:20
Show Gist options
  • Save agc93/b9984b8a3e552632447d60bae16fb6d7 to your computer and use it in GitHub Desktop.
Save agc93/b9984b8a3e552632447d60bae16fb6d7 to your computer and use it in GitHub Desktop.
Running a Ghost blog with MariaDB behind nginx with Docker Compose
version: '2'
services:
proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- '80:80'
- '443:443'
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /etc/nginx/vhost.d # to update vhost configuration
- /usr/share/nginx/html # to write challenge files
- /apps/web/ssl:/etc/nginx/certs:ro # update this to change cert location
ssl-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: ssl-companion
volumes:
- /apps/web/ssl:/etc/nginx/certs:rw # same path as above, now RW
volumes_from:
- proxy
depends_on:
- proxy
mariadb:
image: 'bitnami/mariadb:latest'
volumes:
- 'mariadb_data:/bitnami/mariadb'
blog:
image: 'bitnami/ghost:latest'
expose:
- '2368'
depends_on:
- mariadb
environment:
- VIRTUAL_HOST=your.blog.com
- LETSENCRYPT_HOST=your.blog.com
- [email protected]
@l50
Copy link

l50 commented Aug 28, 2017

Upon running docker-compose up on this, I ran into two issues:

  1. ERROR: Named volume "mariadb_data:/bitnami/mariadb:rw" is used in service "mariadb" but no declaration was found in the volumes section.
    To resolve this, I modified this line:
volumes:
   - 'mariadb_data:/bitnami/mariadb'

to this:

volumes:
   - /mariadb_data:/bitnami/mariadb
  1. At this point, navigating to my URL presents me with this error:
502 Bad Gateway
nginx/1.13.3

@l50
Copy link

l50 commented Aug 28, 2017

It also fails to connect to the database:

Failed to connect to mariadb:3306 after 36 tries

@l50
Copy link

l50 commented Aug 28, 2017

I'm going to document this here incase anyone else was having issues and was interested in getting this working. Here's what my docker-compose.yml looked like in order for me to get a running ghost instance:

version: '2'

services:

  proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /etc/nginx/vhost.d # to update vhost configuration
      - /usr/share/nginx/html # to write challenge files
      - /apps/web/ssl:/etc/nginx/certs:ro # update this to change cert location

  ssl-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: ssl-companion
    volumes:
      - /apps/web/ssl:/etc/nginx/certs:rw # same path as above, now RW
    volumes_from:
      - proxy
    depends_on:
      - proxy

  mariadb:
    image: 'bitnami/mariadb:latest'
    volumes:
       - /mariadb_data:/bitnami/mariadb
    environment:
       - MARIADB_ROOT_PASSWORD=some_rad_password

  blog:
    image: 'bitnami/ghost:latest'
    expose:
      - '2368'
    depends_on:
      - mariadb
    environment:
      - VIRTUAL_HOST=your.blog.com
      - LETSENCRYPT_HOST=your.blog.com
      - [email protected]
    restart: always

@l50
Copy link

l50 commented Aug 28, 2017

Also, thank you very much for your hard work putting together the blog series on how to do this. I know I very much appreciate it, and I'm sure countless other do as well!

@meeeo
Copy link

meeeo commented Dec 15, 2017

Thanks for everyone's hard work, but there's still be a problem with the latest bitmani/mariadb image,
"Error executing 'postInstallation': EACCES: permission denied, mkdir '/bitnami/mariadb" ,
"chown 1001:1001 -R /mariadb_data " solved the problem.

@Taubin
Copy link

Taubin commented Jan 11, 2018

@l50 it's usually better to use restart: unless-stopped instead of restart: always

This will restart the container on a reboot or power failure, but will not automatically restart it if stopped manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment