title: Run script after container entrypoint in docker-compose
body: <p>I have a postgres:9.5.6-alpine container, and another container, named web, which has to be linked to it.
  I want to run a script named <code>create_db.sh</code> in postgres container after it has been started and docker-entrypoint.sh has been executed, in order to create a db and a user and restore a backup.
  My <code>docker-compose.yml</code> (postgres part):</p>
  
  <pre><code>  postgres:
      build: ./postgres
      container_name: postgres
      volumes:
        - /shared_folder/postgresql:/var/lib/postgresql
      ports:
        - "5432:5432"    
      command:  sh /home/create_db.sh
  </code></pre>
  
  <p>The content of <code>create_db.sh</code> is:</p>
  
  <pre><code>#!/bin/sh
  
  psql -d template1 -U postgres
  psql --command "CREATE USER user WITH PASSWORD 'userpassword';" 
  psql --command "CREATE DATABASE userdb;"
  psql --command "GRANT ALL PRIVILEGES ON DATABASE userdb to user;"
  psql --command "\q;"  
  psql -U user -d userdb -f /var/lib/postgresql/backup.sql
  
  exit
  </code></pre>
  
  <p>When i run <code>docker-compose build</code> and then <code>docker-compose up</code> i get this:</p>
  
  <pre><code>Attaching to postgres, web
  postgres    | psql: could not connect to server: No such file or directory
  postgres    |   Is the server running locally and accepting
  postgres    |   connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
  </code></pre>
  
  <p>I've understood this is because when I launch <code>create_db.sh</code> postgres server is not ready, but so how can i run it after the <code>docker-entrypoint.sh</code> of the container?</p>