How to create postgres extension inside the container?

后端 未结 1 1518
醉梦人生
醉梦人生 2020-12-09 10:29

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         


        
相关标签:
1条回答
  • 2020-12-09 10:55

    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.

    0 讨论(0)
提交回复
热议问题