Migrated my blog to Google Cloud and Docker

I finally had time to migrate my blog from DigitalOcean to Google Cloud. I spun off 1 GCE Ubuntu Linux instance and installed the latest version of Docker CE - Community Edition. I ran nginx and ghost as Docker services using Swarm mode.

Here are some references I used to quickly get going with Google Cloud and install Docker in Ubuntu.
https://cloud.google.com/sdk/docs/quickstart-mac-os-x
https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
https://docs.docker.com/engine/installation/linux/linux-postinstall/#manage-docker-as-a-non-root-user

Below is my docker stack yml file.

version: "3.3"
services:

  nginx-service:
    image: nginx
    ports:
      - "80:80"
    networks:
      - web
    deploy:
      replicas: 1
    volumes:
      - /data/docker/volumes/nginx-vol:/etc/nginx
    depends_on:
      - ghost-service

  ghost-service:
    image: ghost
    networks:
      - web
    deploy:
      replicas: 1
    volumes:
      - ghost-vol:/var/lib/ghost/content

networks:
  web:

volumes:
  ghost-vol:

I used nginx to proxy the requests from the outside world and have the blog served by Ghost. Below is my nginx configuration.

location / {
        proxy_pass http://ghost-service:2368;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
    } 

Since I'm running nginx and ghost in Docker swarm mode, I just used the service name (http://ghost-service:2368) to send request to the Ghost service from nginx. Port 2368 is the exposed port for the ghost-service and this port is not require to be binded to the host. The traffic from nginx --> ghost is just within the Swarm routing mesh.

Feel free to drop me a note below if you'd want more information about how I've configured my blog.

Cheers!

Melvin Vivas

Melvin Vivas

Father of 2 wonderful kids, loves programming, wannabee gopher, currently working at an international bank. Bloggin' about Golang, Docker, and Kubernetes.

Read More