Issue
I am using a docker compose for my django app and postgres db. when I have a new migration docker compose up -d --build
clears my data in db. I want to know what is wrong? --build may clear ?
my yaml file:
version: "3.9"
services:
db:
image: postgis/postgis:14-3.2
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=db
- POSTGRES_USER=user
- POSTGRES_PASSWORD=123456
ports:
- "5434:5432"
web:
restart: always
build: .
command:
sh -c "python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
volumes:
- .:/code
ports:
- "7000:8000"
environment:
- POSTGRES_NAME=db
- POSTGRES_USER=user
- POSTGRES_PASSWORD=123456
- UPLOAD_LOCATION_MEDIA=/srv/app/cdn/media
- UPLOAD_LOCATION_IMAGE=/srv/app/cdn/image
depends_on:
- db
Solution
In volumes path of db, map persist path of server to container path. Her the path is:
./data/db:/var/lib/postgresql/data
that should be change to:
/path-to-server-directory/db:/var/lib/postgresql/data
in rebuild db data in server directory will be unchanged.
Answered By - Ali Shekari
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.