title: How to initialize a PSQL database in docker-compose file?
body: <p>I would like to know if it's possible to execute a PSQL command inside the docker-compose file.</p>
  
  <p>I have the following <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3' 
  services:
    postgres:
      image: postgres:9.6
      container_name: postgres-container
      ports:
        - "5432:5432"
      network_mode: host
      environment:
        - LC_ALL=C.UTF-8
        - POSTGRES_DB=databasename
        - POSTGRES_USER=username
        - POSTGRES_PASSWORD=
        - POSTGRES_PORT=5432
  </code></pre>
  
  <p>And After this is running ok, I run the following command:
  <code>docker exec -i postgres-container psql -U username -d databasename &lt; data.sql</code></p>
  
  <p>These 2 steps works fine. But I would ike to know if it's possible to make one single step.</p>
  
  <p>Every time I want to run this command. It's important the database is always new. That's why I don't persist it in a <code>volume</code> and want to run this command.</p>
  
  <p>Is it possible to run <code>docker-compose up</code> and also run the <code>psql</code> command?</p>
  
  <p>Thanks in advance!</p>