R
R
RuslanSer2021-07-31 21:53:05
PostgreSQL
RuslanSer, 2021-07-31 21:53:05

How can you secure Postgresql from accidentally deleting a volume from a Docker database?

In general, there is a project with Django, Postgresql, Docker, and I don't really trust Docker.
Is it possible to somehow protect the volume with the database from accidental deletion (for example, with the docker-compose down -v command) and periodically backup the database?

The docker-compose.yml config is:

version: '3.7'

services:
  db:
    restart: always
    image: postgres:12.0-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=xxxx
      - POSTGRES_PASSWORD=xxxx
      - POSTGRES_DB=xxxxx
    env_file:
      - ./.env.prod
  web:
    restart: always
    build:
      context: ./
      dockerfile: Dockerfile
    command: >
      sh -c "gunicorn -w 2 -b 0.0.0.0:8000 project.wsgi:application"
    volumes:
      #python manage.py migrate
      #python manage.py collectstatic --noinput &&
      #python manage.py runserver 0.0.0.0:8000
      #- .:/home/app/web
      - static_volume:/home/app/web/static
      - media_volume:/home/app/web/media
    #ports:
    #- '8000:8000'
    expose:
      - 8000
    env_file:
      - ./.env.prod
    depends_on:
      - db
  nginx:
    restart: always
    build: ./nginx
    volumes:
      - static_volume:/home/app/web/static
      - media_volume:/home/app/web/media
    ports:
      - 80:80
    depends_on:
      - web

volumes:
  postgres_data:
  static_volume:
  media_volume:

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2021-07-31
@inoise

No one has ever come up with anything more worthwhile than backups and replication. In general, there is nothing to put the database into the container

A
Alexander Karabanov, 2021-07-31
@karabanov

Make bind mounts:

db:
    restart: always
    image: postgres:12.0-alpine
    volumes:
      - /data/postgres_data:/var/lib/postgresql/data/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question