Docker Community Forums

Share and learn in the Docker community.

PostgreSQL is not keeping tables when shutdown - Docker Compose

Folks,
When I run my docker-compose up, I get Postgres working, created a database and created a sample table.
After running docker-compose down and again docker-compose up, I find the database but no tables.

Here is my docker-compose.yml:

version: ‘3.9’

services:
postgres:

command:

- ‘docker volume create db-data’

container_name: postgres
restart: always
image: postgres:latest
environment:
  POSTGRES_PASSWORD: myp4ssw0rd
volumes:
  - ./db-data:/var/lib/postgressql/data
ports:
  - 5432:5432
expose: 
  - 5432
networks:
  - net

pgadmin:
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: “rparente@cfdevelopers.net
PGADMIN_DEFAULT_PASSWORD: “myp4ssw0rd”
PGADMIN_LISTEN_PORT: “80”
ports:
- “8080:80”
depends_on:
- postgres
volumes:
- ./pgadmin-data:/var/lib/pgadmin
networks:
- net

lucee:
container_name: lucee
image: lucee/lucee
volumes:
- ./www:/var/www
- ./password.txt:/opt/lucee/server/lucee-server/context/password.txt
ports:
- 4040:8888
depends_on:
- postgres
networks:
- net

networks:
net:

volumes:
db-data:
name: db-data
external: true
pgadmin-data:
name: pgadmin-data
external: true

What am I doing wrong ?
I tested with and without the below Dockerfile:

FROM postgres:latest

RUN mkdir -p /var/lib/postgresql/data
ENV PGDATA /var/lib/postgresql/data

Thanks in advance for your help !

vs.

those are not the same folders, are they? While the 2nd quoted block uses the correct path, the 1st quoted block maps the host folder into the wrong folder inside the container. As a result the data is written into the container - and gets destroyed with the container.

Also none of the declared volumes are used in the service’s volume mapping: