I’m trying to run a PostgreSQL container in Docker using the following command:
docker run -e POSTGRES_PASSWORD=a -v /root/docker/postgres/data:/var/lib/postgresql/data:rw -p 5432:5432 mypostgres
However, the container is not starting, and I’m getting the following message:
PostgreSQL Database directory appears to contain a database; Skipping initialization
I have a directory on my host where my database files are stored, but nothing seems to be starting.
Here are the steps I’ve tried so far:
Checked the logs of the container:
docker logs b3ea574a51ee
The logs didn’t show any additional errors beyond the message above. Here are the logs I found:
2024-07-22T00:38:45.033287950Z SENTENCIA: SELECT * FROM logistica.vw_web_req where nlineno= and req_anio='' 2024-07-22T05:51:18.788515074Z LOG: el de paquete de inicio tiene largo incorrecto 2024-07-22T13:56:38.867808926Z 2024-07-22T13:56:38.868709324Z PostgreSQL Database directory appears to contain a database; Skipping initialization 2024-07-22T13:56:38.868728852Z 2024-07-22T13:57:31.512410811Z 2024-07-22T13:57:31.512503278Z PostgreSQL Database directory appears to contain a database; Skipping initialization 2024-07-22T13:57:31.512513417Z
Checked the status of the container:
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b3ea574a51ee mypostgres "docker-entrypoint.s…" 5 months ago Exited (132) About an hour ago kind_mahavira
Tried running the container without mounting the volume:
docker run -e POSTGRES_PASSWORD=a -p 5432:5432 mypostgres
This worked, indicating the issue might be related to the existing data in the mounted volume.
Additional context:
The PostgreSQL container was running fine initially.
I left it running overnight, and by the next morning, it had stopped.
The logs suggest it stopped at 2024-07-22T05:51:18.788515074Z with the message “el de paquete de inicio tiene largo incorrecto.”
I’m not sure what else to check or how to resolve this issue. Any help or guidance would be greatly appreciated!
Additional Information:
Docker version: 27.1.0
PostgreSQL image (Dockerfile):
`FROM postgres:9.5.25
RUN localedef -i es_PE -c -f UTF-8 -A /usr/share/locale/locale.alias es_PE.UTF-8
ENV LANG es_PE.UTF-8
ENV LC_ALL es_PE.UTF-8
ENV TZ America/Lima
ENV PGTZ America/Lima`
Host OS: Ubuntu 22.04.4 LTS