Dockerized postgres restarts `postgres` user password

  django, docker, docker-compose, postgresql, psql

I’m running web app and postgres in docker containers inside VM and every once in a little while postgres docker resets user password but data remains. This makes application fails calling postgres db. I’d have to access ssh and run ALTER USER postgres WITH PASSWORD ‘postgres’; to fix it every time them it’d run fine for a day or two sometimes more.

Here is the log before the error occurs:
https://imgur.com/FxwiDMY

Has anyone seen any similar problems or any idea what’s going on?

My docker-compose.yml :

version: '3.4'
  
services:
  postgres:
    image: postgres:latest
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - ${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}
  redis:
  ...
  web:
  ...

volumes:
  db-data:
    driver: local

EDIT: I copied wording from here since this was exactly the same problem I am facing. https://www.digitalocean.com/community/questions/postgres-docker-in-droplet-resets-user-password-on-its-own

The app I am running is Django and I know for a fact that in settings.py I get correct password – 'postgres'. It must be docker/postgres combo fault and it seems that the password is reset from time to time (every 1-2 days).

Django log: enter image description here

Source: Docker Questions

LEAVE A COMMENT