0
version: '3'

services:
  db:
    image: postgres
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
  web:
    build: .
    command: python3 manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db
  • Is this configuration safe to work with PostgreSQL using docker ?
  • Do I need any more configurations to make it safer (eg: .dockerignore) ?
  • Is theire a risk that volumes work on two way binding and that may cause data loose ?

1 Answer 1

1

The important part of the postgres container, so backing up the data folder is enough. Starting a new container is cheap in your situation, the data is what is important.

The there no obvious reason for why the volume won't work, unless you delete the postgres-data folder accedentaly.

In summary, by inspecting the compose file, things are normal and safe.

Sign up to request clarification or add additional context in comments.

3 Comments

TY. Do I need to .gitignore postgres-data folder ? Do I need to .dockerignore it ?
Since the postgres-data folder and Dockerfile for web are in the same directory, the data folder will be sent to the deamon when building the image. This is unncessary. It will also be mounted into the web container due to volume - .:/code. It might be better to move the postgres-data folder to another localtion, something like ../postgres-data
TY. I prefere using .dockignore instead, this way I wont need to change my folder structure "flat is better than nester"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.