Still getting my docker sea legs, I am trying to create a container for postgres 14 with alpine linux.
this is my Dockerfile
so far:
FROM alpine:3.15.5
EXPOSE 5432
# update repo, install postgres 14
RUN apk update
RUN apk add gcc make
RUN apk add postgresql14 postgis
# data dir
RUN mkdir /var/lib/postgresql/data
RUN chmod 0700 /var/lib/postgresql/data
RUN chown postgres:postgres /var/lib/postgresql/data
VOLUME /var/lib/postgresql/data
# create db cluster as postgres user
USER postgres:postgres
RUN initdb -D /var/lib/postgresql/data
# temp
ENTRYPOINT [ "top" ]
The issue I am running into is when I build and run (docker-compose up --build
), the initdb command runs perfectly, no errors, and the output makes sense, however there is no data in the /var/lib/postgresql/data
dir which should have all the default postgres configs and db files.
The weird thing is, if I attach the container shell while it is running, and run initdb -D /var/lib/postgresql/data
it works...
Please can you tell me what I am doing wrong/missing
Here is the docker-compose.yml
as well for total coverage:
version: '3.9'
services:
postgres:
build: .
ports:
- "5432:5432"
volumes:
- ./postgres:/var/lib/postgresql/data