When setting up this blog I wanted to host it myself and all within Docker from one script, So I could run it up quick on a new box or move it into the cloud later.
I found some good guides online but didn’t find one that had everything I wanted in one place, I found that they would have a good setup for ghost but didn’t have the reverse proxy or letsencrypt in dockers. I really wanted everything to be in one place to be able to move it quick or run it up again fast.
I ended up using three dockers, a nginx-proxy docker to reverse proxy connects to the docker host from the internet to the blog. Then a letsencrypt docker to get a SSL cert for the site and finely the blog it’s self running on ghost.
First we setup the nginx reverse using the nginx-proxy docker, you will need to have port 80 and 443 open from the internet to your docker host and point your domain to that host for this to work. I’m using cloudflare for my domains DNS but anything should work. more can be found on this here cloudflare
Open nano on your docker host to start setting up a script
sudo nano create.sh
Copy and past the three docker run commands into the script
docker run -d -p 80:80 -p 443:443 \
--name nginx-proxy \
-v /home/user/docker/certs:/etc/nginx/certs:ro \
-v /etc/nginx/vhost.d \
-v /usr/share/nginx/html \
-v /var/run/docker.sock:/tmp/docker.sock:ro \
--label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true \
jwilder/nginx-proxy
With this next part we use the letsencrypt docker to get a SSL cert for our blog
docker run -d \
--name nginx-letsencrypt \
--volumes-from nginx-proxy \
-v /home/user/docker/certs:/etc/nginx/certs:rw \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
jrcs/letsencrypt-nginx-proxy-companion
Then last but not least is the ghost blog it’s self.
docker run --name blog --expose 2368 -d \
-e PROD_DOMAIN=https://berry.net.au \
-e NODE_ENV=production \
-e PROD_MAIL_TRANSPORT=SMTP \
-e PROD_MAIL_HOST:mail.internode.on.net \
-e PROD_MAIL_FROM:[email protected] \
-e PROD_MAIL_SECURE_CONNECTION:false \
-e PROD_MAIL_PORT:25 \
-e VIRTUAL_HOST=blog.dberry2.com \
-e "LETSENCRYPT_HOST=blog.dberry2.com" \
-e "[email protected]" \
-v /home/user/docker/blog/:/var/lib/ghost \
zzrot/alpine-ghost
Save the script by pressing Ctral + X then Y to save
Make the script executable by running
sudo chmod +x create.sh
Now everything need for a quick blog to be setup on docker host
Start the blog by running the new script
sudo sh create.sh
You should now see the docker host download and start the reverse proxy, get an SSL cert from letsencrypt and then start the blog.
Give it a tad bit of time and then go to the blogs admin page to start setting it up, it should be blog.yourdomain.com/admin
If you later need to move your site to a new host / into the cloud all you need to do is copy your docker data the /docker folder in your user drive and the create.sh script to a new host, update DNS on your domain and start it back up.