I have to install hstore
to my docker postgres
Here is my ordinary command in the shell to execute my need
psql -d template1 -c \'create
It's failing because Postgres isn't running in the container during the build, it's only started in the CMD
when a container runs.
The entrypoint script for the Docker image has support for running setup steps - any .sql or .sh files in the /docker-entrypoint-initdb.d
directory will be executed when the container starts.
So you can do this by putting your extension setup in a SQL script, and copying the script into the image in the init directory:
> cat hstore.sql
create extension hstore
> cat Dockerfile
FROM postgres:9.5
COPY hstore.sql /docker-entrypoint-initdb.d
When you build that image, the SQL script will be in the right place to be executed, so whenever a container runs from the image it will install the extension.