PostgreSQL Custom Docker Image With Volume Entrypoint Questions

Hello, I have a Docker Image for PSQL with a volume attatched to that service that I am trying to run, on initial startup however, I get the following: PostgreSQL Database directory appears to contain a database; Skipping initialization. How can I have a volume attached but still get this to run? Thanks!
Solution:
your dockerfile would need to copy the docker-entrypoint-initdb.d file into the applicable location
Jump to solution
13 Replies
Percy
Percy5mo ago
Project ID: b2136db9-ae75-4237-ac77-4e079154cc94
coloneljelly
coloneljellyOP5mo ago
b2136db9-ae75-4237-ac77-4e079154cc94
Brody
Brody5mo ago
please add more context
coloneljelly
coloneljellyOP5mo ago
Dockerfile:
FROM pgvector/pgvector:pg16
RUN apt-get update && apt-get install -y postgis postgresql-16-postgis-3
FROM pgvector/pgvector:pg16
RUN apt-get update && apt-get install -y postgis postgresql-16-postgis-3
Docker Compose:
version: '3.1'

services:
db:
image: postgis_and_pg_vector:latest
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
RAG_USER_PASSWORD: ${RAG_USER_PASSWORD}
PGDATA: ${PGDATA}
ports:
- "5432:5432"
volumes:
- ./init:/docker-entrypoint-initdb.d
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
version: '3.1'

services:
db:
image: postgis_and_pg_vector:latest
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
RAG_USER_PASSWORD: ${RAG_USER_PASSWORD}
PGDATA: ${PGDATA}
ports:
- "5432:5432"
volumes:
- ./init:/docker-entrypoint-initdb.d
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Volume is mounted at /var/lib/postgresql/data PGDATA is currently set at /var/lib/postgresql/data/pgdata
Brody
Brody5mo ago
railway services can not have two volumes
coloneljelly
coloneljellyOP5mo ago
Gotcha What approach would you recommend here?
Solution
Brody
Brody5mo ago
your dockerfile would need to copy the docker-entrypoint-initdb.d file into the applicable location
coloneljelly
coloneljellyOP5mo ago
Okay makes sense, thanks!
Brody
Brody5mo ago
but even so, its a init script and will not be ran on every redeploy, it will only be ran if there is an empty data volume
coloneljelly
coloneljellyOP5mo ago
Yeah that's fine. I'm assuming adding a volume is the only way to persist data in a Railway service? Or will it do it by default?
Brody
Brody5mo ago
you are correct, volumes are the only way to persist files on disk can you add some more context though? what does docker-entrypoint-initdb.d do?
coloneljelly
coloneljellyOP5mo ago
Just creates some tables and sets up permissions. I only need it on the original creation of the DB
Brody
Brody5mo ago
then yeah, copy it into the correct location, and then wipe the volume to allow it to run again
Want results from more Discord servers?
Add your server