jwasham / docker-ghost-template

Docker composition of Ghost blog with Node, NGINX proxy, database, etc.
61 stars 26 forks source link

docker-ghost-template

Docker composition of Ghost blog with Node, NGINX proxy with SSL termination, database, etc.

Software Used

Docker version 1.10.3

docker-compose version 1.6.2

The Stack

Inherited Image Versions

What You'll Need

How to Use It

  1. Clone project to your server's filesystem.
  2. Edit environment settings in docker-compose.yml
    • blog domain
    • database settings - in 2 places - under ghost, and under mysql.
    • mail server settings
    • S3 bucket and S3 info
    • CloudFront domain
  3. Add your SSL certificate and key to nginx/volumes/ssl/ (there are placeholders there)
  4. Set the blog domain (server_name) in nginx/copy/default.conf (must match the common name in your SSL certificate)
  5. Run from within your Linux environment or Docker Toolbox environment:
    1. docker-compose build
    2. docker-compose up -d (you can remove the -d if you want to see logs, then Ctrl+C to stop all containers)
  6. If using Docker Toolbox, look up the host IP address with: docker-machine ip default
  7. On Linux, you'll just use "localhost" or "127.0.0.1".
  8. Switch your domain's DNS to point to the address. Go to the domain in our browser and you'll see your new blog.
  9. Go to https://YOUR_DOMAIN/admin to set up your blog.
  10. Once you've made your admin account using that wizard, go back to: https://YOUR_DOMAIN/admin
  11. Log in and enjoy.

Ghost Content Directory

The directory ghost/volumes/content will be populated with 5 directories and a file the first time you start the container.

Ghost will create these directories:

How to back up your database

  1. Run "docker-compose ps" to get a list of running containers.
  2. Locate the name of the mysql container.
  3. Run this command to get the container's internal IP: docker inspect --format='{{.NetworkSettings.IPAddress}}' THAT_CONTAINER-NAME
  4. In your favorite database GUI tool (like Navicat or DataGrip), create a new connection via SSH tunnel to the host machine
  5. Use the internal IP address and database user and password to connect to database once SSH tunnel is established to host.
  6. You'll have access to the data so you can view data and run backups.

Theme

The default theme is Casper. I have a minor fork of this theme here: https://github.com/jwasham/casper-startup-next-door

It includes Disqus support, so all you have to do is change the identifiers to your blog's Disqus ID and domain and you're good to go. See the README in that repo.

To install another theme

Stop docker-compose with:

docker-compose stop

Copy the new theme to docker-ghost-template/ghost/volumes/content/themes/ so that your theme folder sits next to the casper folder in the themes directory

Now run: docker-compose up -d

Log in to the Ghost admin, go to Settings > General, and at the bottom is the Theme dropdown. Select your theme and click Save.

How does that work?

The ghost/volumes/content directory (on docker host machine) gets mounted inside your ghost container at /var/lib/ghost when the container runs. See the docker-compose.yml to see where this volume mount is happening.

Security

To Upgrade from an Earlier Ghost version

Docker containers are meant to be disposable, so you'll need to export your Ghost data first.

  1. Export your data: https://help.ghost.org/hc/en-us/articles/224112927-Import-Export-Data
  2. Set up a new server with the repo.
  3. Set it up as directed.
  4. Create your admin account via the web-based wizard.
  5. Delete the starter post.
  6. Go to Labs and import your data.

That's it!

MySQL memory

I'm running this on an EC2 t2.micro at 1GB RAM. I tried to limit MySQL's memory limit because it was taking up, what in my opinion, was too much.

Adding this to the mysql: block in docker-compose.yml will limit memory:

mem_limit: 384m

I tried 256 and 384. Both caused issues with MySQL. Instead of continuing to experiment, or trying to tune MySQL in a container (no thanks), I just removed the limit.