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 !

2
  • It may be useful: stackoverflow.com/questions/29600369/… Commented Feb 15, 2016 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 Commented Feb 16, 2016 at 10:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.