I’ve got a 2GB Basic (22.04) Droplet running Docker for a my portfolio site (currently, will be hosting my other projects to display my previous projects). I’m new to Docker being ran for production, I’ve been using it mainly to run postgres, elasticsearch for development. Below is my docker-compose file for the current build I am having issues with.
version: "3.10" services: backend: build: context: . dockerfile: Dockerfile restart: always volumes: - static_volume:/backend/static - media_volume:/backend/media ports: - "8000:8000" command: > sh -c "python manage.py collectstatic --noinput && python manage.py migrate && gunicorn project.wsgi:application --bind 0.0.0.0:8000" depends_on: - db db: image: postgres volumes: - postgresdata:/var/lib/postgresql/data:rw env_file: - ".env" ports: - "5432:5432" container_name: xxxx_db frontend: build: context: ./frontend dockerfile: Dockerfile volumes: - frontend_build:/frontend/build nginx: image: nginx:latest restart: always ports: - "81:8080" volumes: - ./nginx/nginx-setup.conf:/etc/nginx/conf.d/default.conf:ro - frontend_build:/var/www/frontend - static_volume:/var/www/backend/static - media_volume:/var/www/backend/media depends_on: - db - backend - frontend volumes: frontend_build: static_volume: media_volume: postgresdata
It seems that every night the db is just being wiped, I’m able to re-run the migrations, docker compose down and up where the data will persist. But in the morning I get a bunch of errors from django implying that the database is no longer there.
I checked the xxxx_db logs and noticed this in the early hours of the morning:
2023-11-10 00:50:06.222 UTC  FATAL: expected SASL response, got message type 0 2023-11-10 01:09:59.536 UTC  FATAL: unsupported frontend protocol 0.0: server supports 3.0 to 3.0 2023-11-10 01:09:59.823 UTC  FATAL: unsupported frontend protocol 255.255: server supports 3.0 to 3.0 2023-11-10 01:10:00.117 UTC  FATAL: no PostgreSQL user name specified in startup packet 2023-11-10 01:35:07.437 UTC  FATAL: database "template0" is not currently accepting connections 2023-11-10 01:37:09.770 UTC  ERROR: cannot drop the currently open database 2023-11-10 01:37:09.770 UTC  STATEMENT: DROP DATABASE postgres; 2023-11-10 01:37:10.886 UTC  ERROR: cannot drop a template database 2023-11-10 01:37:10.886 UTC  STATEMENT: DROP DATABASE template1; 2023-11-10 01:37:12.020 UTC  ERROR: cannot drop a template database 2023-11-10 01:37:12.020 UTC  STATEMENT: DROP DATABASE template0;
Any help would be greatly appreciated as it’s driving me insane!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.