I am using postgres with docker and having trouble with it. I successfully docker-compose up --build
When I run below command it works fine. psql starts with my_username user as expected. I can see my database, \l, \dt commands works ok.
docker-compose exec db psql --username=my_username --dbname=my_database
But when I run below commands I get error role “postgres” does not exist,
Additionally \l, \dt not works, even psql command not works
docker exec -it my_db_container_1 bash
su - postgres
createuser --createdb --password new_user
How can I get it right in the second case? What is going wrong? I am confused
docker-compose.yml
version: "3.9"
services:
#### other services ####
db:
image: postgres:latest
restart: always
environment:
POSTGRES_DB: my_database
POSTGRES_USER: my_username
POSTGRES_PASSWORD: my_password
ports:
- 5432
volumes:
- postgres_data:/var/lib/postgresql/data/
volumes:
postgres_data: