Reputation: 6588
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?
Upvotes: 0
Views: 1094
Reputation: 28533
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.
Upvotes: 5