3

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.

Scottie
  • 1,021
  • 2
  • 14
  • 22
  • 1
    if your disk attached to VM you can use it I think by just changing the mount path in docker-compose and writing all the data inside the disk. – Harsh Manvar Apr 19 '21 at 09:01
  • @HarshManvar The GCP disk can be only mounted to one VM at the same time. I mounted it from 'VM instances' > 'VM instance details' > 'edit' > 'Additional disks' – Scottie Apr 19 '21 at 09:12
  • Are you able to set up this configuration in your local environment? if so, can you share how you did? – guillaume blaquiere Apr 19 '21 at 12:15
  • @guillaumeblaquiere I use `nfs` in the development environment. However, I cannot find the document using `nfs` to connect to GCP disk/storage bucket. – Scottie Apr 19 '21 at 15:24
  • Have a look to [memorystore](https://cloud.google.com/memorystore) ;) – guillaume blaquiere Apr 19 '21 at 18:59

2 Answers2

2

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
Divick
  • 1,213
  • 1
  • 20
  • 44
1

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)
Scottie
  • 1,021
  • 2
  • 14
  • 22