0

I'm trying to create a docker image with postgres AND some users, schema and data.

I don't want to use docker-entrypoint-initdb.d because database will be initialize in docker run step, i want all my data avalaible when docker run. So i'm trying to build an image with some users, schema and data, but i can't do that.

(I'm trying to do that for launching automated unit test who start my docker postgres Database. The purpose of this is to avoid data initialization and providing same docker database for all coworkers)

I have reading some doc about VOLUMES, data-container, etc... but it doesn't give a independent container I have tryed something like that, but no data were present when starting my container

FROM postgres:9.4

RUN mkdir -p /var/lib/pgdata RUN chown -R postgres /var/lib/pgdata ENV PGDATA /var/lib/pgdata VOLUME /var/lib/pgdata

COPY init_database.sql /init/init_database.sql

RUN /etc/init.d/postgresql start && pg_createcluster 9.4 main --start

USER postgres

RUN /etc/init.d/postgresql start &&\ psql --command "CREATE USER user0 WITH PASSWORD 'user0';"

USER root

Thanks for helping !

Couturier Boris
  • 198
  • 1
  • 10
  • It may be useful: http://stackoverflow.com/questions/29600369/starting-a-postgres-container-in-docker-and-then-loading-it-with-data – JesusTinoco Feb 15 '16 at 20:06
  • I have already found this post, but the solution create data at 'docker run' step into container, not at 'docker build' step into image – Couturier Boris Feb 16 '16 at 10:29

0 Answers0