title: Initialize Postgres db in Docker Compose
body: <p>I have the following <code>docker-compose.yml</code> file:</p>
  
  <pre><code>version: '3'
  
  services:
    postgres:
      image: postgres
      container_name: postgres
      ports:
        - "5431:5432"
      environment:
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=postgres
        - POSTGRES_DB=anime
      volumes:
        - ./init.sql:/docker-entrypoint-initdb.d/init.sql
  </code></pre>
  
  <p>This configuration starts a Postgres database. In volume I defined init.sql, which should set up a table:</p>
  
  <pre><code>CREATE TABLE anime ( 
    anime_id INT PRIMARY KEY,
    title TEXT
  );
  </code></pre>
  
  <p>Then, I would like to fill the Postgres database with data from the CSV file.</p>
  
  <p>I tried to add another volume to docker-compose:</p>
  
  <pre><code> - ./preload.sql:/preload/preload.sql
  </code></pre>
  
  <p>with that script:</p>
  
  <pre><code>copy anime FROM 'docker/data/AnimeList.csv' DELIMITER ',' CSV HEADER;
  </code></pre>
  
  <p>The CSV file is located in the <code>data</code> folder, on the same level as <code>docker-compose.yml</code>.</p>
  
  <p>But it is not working. The database is created correctly, but it doesn't have the table and data. When I connect to Docker container, run <code>'psql</code> command and try to get <code>anime</code> table, I get the following error:</p>
  
  <pre><code>Did not find any relation named "anime".
  </code></pre>
  
  <p>My question is: how to preload the Postgres container with the CSV data file in docker-compose?</p>