0

I am trying to run a Dockerfile that run PostgreSQL and then add some tables to it.

This is my Dockerfile:

FROM postgres:9.6

MAINTAINER [email protected]

USER postgres
ADD ./backup.sql /backup.sql
ADD ./deploy/import_database.sh /import_database.sh

USER root
RUN chmod +x /import_database.sh

USER postgres

ENTRYPOINT ./docker-entrypoint.sh postgres
CMD ./import_database.sh

The entrypoint doesn't finish becouse it runs the postgres server. How can I run the CMD for example, after 20 seconds of running the ENTRYPOINT, but without finishing the ENTRYPOINT?

Is it possible?

1 Answer 1

5

This is not how the CMD and ENTRYPOINT work. I'd recommend reading https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact and checking the chart for a better understanding of how the ENTRYPOINT and CMD interact with each other.

That said, if all you want to do is import a SQL file or run a script at runtime, the official PostgreSQL image already has you covered. See https://github.com/docker-library/docs/tree/master/postgres#how-to-extend-this-image for information on how to do this.

An example in the case of your Dockerfile (if you just wanted to import the SQL file) would be to do something like:

FROM postgres:9.6
ADD ./backup.sql /docker-entrypoint-initdb.d/backup.sql

When starting a container from the image build on this Dockerfile, the default ENTRYPOINT script will start a temporary PostgreSQL instance, wait for it to be ready, import your data, and then restart to serve connections.

1
  • Really thanks!! It works perfect for me :) , I would read it how CMD and ENTRYPOINT works together. Jul 6, 2017 at 6:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.