Docker persistent volume on GCP

Viewed 1774

I'm deploying services to GCP and I want to persist the database and logs.

The VM's local storage is not considered.

How can I mount the GCP disk/bucket to the containers?

Here is my docker-compose.yml:

version: '3'
services:
  backend:
    image: mybackend:latest
    volumes:
      - logs-data:/path/to/logs

  database:
    image: postgres:12.6-alpine
    volumes:
      - db-data:/var/lib/postgresql/data
      - logs-data:/var/log/postgresql

volumes:
  db-data:
    driver: ??
    driver_opts: ??

  logs-data:
    driver: ??
    driver_opts: ??

The gcePersistentDisk is for Kubernetes only.

2 Answers

The Docker built-in driver local only supports NFS and bind (bind to local file system).

The bind is not considered a solution because containers will not be in the same node.

These are possible solutions from Google:

  1. Create another container to be the NFS host
  2. Create multiple containers to compose a GlusterFS cluster, and use NFS to connect to it
  3. Install 3rd-party driver plugin REX Ray (the repo is inactive)

You can use gcsfuse to create a docker volume which stores data in google cloud storage.

  1. First install gcsfuse as mention in [gcsfuse] docs.
  2. Create a google cloud storage bucket
  3. Mount the bucket on your local filesystem using gcsfuse
  4. Bind mount of this filesystem 5
Related