How do I create a template from the following Docker files?

Dockerfile
FROM postgres:16-alpine3.19

RUN apk -U add --no-cache \
alpine-sdk \
curl-dev \
clang15 \
llvm15 \
perl

RUN git clone https://github.com/supabase/pg_net.git

RUN cd pg_net && \
make && make install

RUN cd / && \
rm -rf pg_net && \
apk cache clean

RUN echo '#!/bin/bash' > /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'set -e' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'CREATE USER postgres;' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'ALTER ROLE postgres SUPERUSER;' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'CREATE EXTENSION IF NOT EXISTS pg_net;' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'EOSQL' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
chmod +x /docker-entrypoint-initdb.d/00-pg-net.sh
FROM postgres:16-alpine3.19

RUN apk -U add --no-cache \
alpine-sdk \
curl-dev \
clang15 \
llvm15 \
perl

RUN git clone https://github.com/supabase/pg_net.git

RUN cd pg_net && \
make && make install

RUN cd / && \
rm -rf pg_net && \
apk cache clean

RUN echo '#!/bin/bash' > /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'set -e' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'CREATE USER postgres;' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'ALTER ROLE postgres SUPERUSER;' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'CREATE EXTENSION IF NOT EXISTS pg_net;' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
echo 'EOSQL' >> /docker-entrypoint-initdb.d/00-pg-net.sh && \
chmod +x /docker-entrypoint-initdb.d/00-pg-net.sh
docker-compose.yml
version: '3.7'

services:
postgres:
build:
context: .
image: postgresql:16-alpine3.19-pg_net
ports:
- '5432:5432'
command: postgres -c shared_preload_libraries=pg_net -c pg_net.database_name=${POSTGRES_DB} -c max_connections=200
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped

volumes:
postgres_data:
version: '3.7'

services:
postgres:
build:
context: .
image: postgresql:16-alpine3.19-pg_net
ports:
- '5432:5432'
command: postgres -c shared_preload_libraries=pg_net -c pg_net.database_name=${POSTGRES_DB} -c max_connections=200
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
restart: unless-stopped

volumes:
postgres_data:
18 Replies
Brody
Brody7mo ago
can you help me to understand this? the dockerfile is for postgres and the docker compose file also deploys postgres?
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
I'm installing a supbase postgres extension called pg_net There are some steps required to get installed, which is installing packages, cloning the git repo and actually installing it Then we have to set these values shared_preload_libraries = pg_net pg_net.database_name = ${POSTGRES_DB} Then we run this command CREATE EXTENSION IF NOT EXISTS pg_net; And that's all
Brody
Brody7mo ago
in the docker compose file it looks like a pre-built image for that already exists, why not just deploy the standard postgres database on railway and then swap it's source image for your desired image?
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
Basically beecause I have the run this compose postgres -c shared_preload_libraries=pg_net -c pg_net.database_name=${POSTGRES_DB} -c max_connections=200 Which I'm currently running in my docker compose
Brody
Brody7mo ago
what's stopping you from put that as the start command?
/bin/sh -c "exec postgres -c shared_preload_libraries=pg_net -c pg_net.database_name=${POSTGRES_DB} -c max_connections=200"
/bin/sh -c "exec postgres -c shared_preload_libraries=pg_net -c pg_net.database_name=${POSTGRES_DB} -c max_connections=200"
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
Hi so I did this and app has been deploying for 5 minutes Logs are empty Here's a link to the image https://hub.docker.com/r/babkum/postgres-essentials
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
And a link to the Github repository https://github.com/babkum/postgres-essentials
GitHub
GitHub - Babkum/postgres-essentials: A postgres image with some ext...
A postgres image with some extensions built-in. Contribute to Babkum/postgres-essentials development by creating an account on GitHub.
Brody
Brody7mo ago
show me what you changed after deploying the standard postgres database
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
Ok I took a different approach now, you can check the same repo Application is deploying and starting fine now but can't connect I'm not sure but I think it's a common issue
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
No description
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
How can I fix it?
Brody
Brody7mo ago
the tcp proxy most certainly isn't using port 5432
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
Ok I tried the other port and didn't work The other port being the one in the env
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
No description
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
No description
Brody
Brody7mo ago
this screenshot is cut off did you really open 7 duplicate threads?
Faruq Alli-Balogun
Faruq Alli-BalogunOP7mo ago
Oh no I think it’s a bug. I clicked on Submit, I didn’t get any feedback and the pop up was still open So I thought I had network issues That’s where the error is
Brody
Brody7mo ago
interesting, alright fair enough I can't blame you for that then haha
Want results from more Discord servers?
Add your server