0

I have a project where I use google compute engine to host my app and docker to containerize it.

I have a postgres image and I want to use a volume to make my data persistent when I restart the container. Moreover I want the db data to be stored in google storage. So I have a google storage bucket and I have mounted a directory in my google compute engine to that bucked. Specifically what I did is mkdir /home/vetter_leo/data where data is the folder I want to use as a volume and then I mount it using gcsfuse --dir-mode 777 --file-mode 777 -o allow_other --implicit-dirs artifacts.helenos-273112.appspot.com /home/vetter_leo/data/.

My dockerfile for the postgres image is this :

FROM postgres:latest

USER postgres

ENV POSTGRES_USER helenos
ENV POSTGRES_PASSWORD helenos
ENV POSTGRES_DB helenos
ENV PGDATA /var/lib/postgresql/data/pgdata

COPY init_helenos_schema.sql /docker-entrypoint-initdb.d/

EXPOSE 5432

and my docker-compose file is this :

version: "3.5"

services:

  postgres:
    container_name: postgres
    image: postgres
    build:
      context: .
      dockerfile: ./postgres.prod.dockerfile
    volumes:
      - /home/vetter_leo/data:/var/lib/postgresql/data

networks:
  default:
    external:
      name: helenos-network

When doing docker-compose -f docker-compose.yml up -d --build I end up with the container not being started and this error is shown chmod: changing permissions of '/var/lib/postgresql/data/pgdata': Operation not permitted.

I have searched the web but so far I have not been able to find a solution for my problem. Any help would be greatly appreciated. Thanks.

Andrew Gaul
  • 2,296
  • 1
  • 12
  • 19
Vetouz
  • 159
  • 3
  • 19
  • This approach does not seem optimal in terms of performance and data consistency because DB data will be transferred over the network on every change. Why not use a [persistent disk](https://cloud.google.com/compute/docs/disks/add-persistent-disk)? – mebius99 Apr 27 '20 at 21:18
  • After confirming that the persistent disk is a solution for this case, everything that did not fit in a short comment, is posted as a full answer. – mebius99 May 04 '20 at 13:07

1 Answers1

0

I ended up using a persistend disk as sugested by @mebius99 and it works so no problem anymore.

Vetouz
  • 159
  • 3
  • 19