How to create postgres extension inside the container?
<p>I have to install <code>hstore</code> to my docker postgres<br>
Here is my ordinary command in the shell to execute my need<br></p>

<pre><code>psql -d template1 -c 'create extension hstore';
</code></pre>

<p>If I remove that line my container, it works, but I have execute <code>hstore</code> installation by myself and I have to tell everyone in my project to do so which is not a good practice</p>

<p>Here is my <code>yml file</code></p>

<pre><code>  postgres:
    build:
      context: .
      dockerfile: dockerfiles/devdb.dockerfile
    environment:
      POSTGRES_USER: uih
      POSTGRES_PASSWORD: uIhbod!
      POSTGRES_DB: uih_portal
    ports:
        - "5433:5432"
</code></pre>

<p>Here is my docker file <code>devdb.dockerfile</code><br></p>

<pre><code>FROM postgres:9.5

RUN mkdir -p /var/lib/postgresql-static/data
ENV PGDATA /var/lib/postgresql-static/data

# psql -d template1 -c 'create extension hstore;'
CMD ["psql", "-d", "template1", "-c", "'create extension hstore;'"]

RUN echo "hstore extension installed"
</code></pre>

<p>After build I can not get it run<br></p>

<pre><code>$ docker-compose up postgres
Recreating uihportal_postgres_1
Attaching to uihportal_postgres_1
postgres_1       | psql: could not connect to server: No such file or directory
postgres_1       |      Is the server running locally and accepting
postgres_1       |      connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
uihportal_postgres_1 exited with code 2
</code></pre>

<p><strong>Question:</strong></p>

<p>How to install <code>hstore</code> from the dockerfile?<br>
I want to make an image and re-use it for the entire project for my team</p>