-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docker-entrypoint-initdb.d #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello, if you want to also insert data be sure to add a |
I'm also interested in having a lightweight container that instantly spins up with some pre-built data. Just doing Was trying 1000's variations of the following, but with no luck so far: FROM postgres:9.5-alpine AS data-donor
COPY etc/db/ /docker-entrypoint-initdb.d/
RUN docker-entrypoint.sh
ENTRYPOINT ["/bin/sh"]
FROM postgres:9.5-alpine
COPY --from=data-donor /var/lib/postgresql/data /var/lib/postgresql/data/ According to the logs of the donor intermediate container, the data does load, but when I Having an example on https://hub.docker.com/_/postgres/ would save people hundreds of hours! I guess the situations when the data is bound with the lightweight autonomous containers become more often as people move their microservices into kubernetes clusters and docker swarms. |
The "/var/lib/postgresql/data" directory is a volume, so you cannot
pre-populate it. You can set PGDATA to override the location to somewhere
that isn't a volume, or you could build your own image that does not
include the VOLUME declaration.
|
Awesome, thanks for the hint @tianon! This worked: FROM postgres:9.5-alpine AS data-donor
RUN apk add --no-cache unzip
COPY etc/db/ /docker-entrypoint-initdb.d/
ENV PGDATA=/pgdata
RUN docker-entrypoint.sh --help
FROM postgres:9.5-alpine
ENV PGDATA=/pgdata
COPY --from=data-donor /pgdata /pgdata
RUN chown -R postgres:postgres /pgdata I'm adding Problem solved! Your hint about the VOLUME was the key! UPD: The container starts, but there are still some issues: #319 |
Thanks, use "COPY db/ /docker-entrypoint-initdb.d/" work. |
@hunsche that's also an option, just bear in mind that your DB will be restored from a dump on each container start. Doing the build in two stages will give you faster launch times. |
How do I create a database in the docker-entrypoint-initdb.d directory?
Need to create an image where it already comes with some database created.
The text was updated successfully, but these errors were encountered: