title: Run `rails db:setup` in Docker with schema in structure.sql
body: <p>I have a new Rails app that I am planning to deploy in a Docker container. We are using <code>structure.sql</code> instead of <code>schema.rb</code>. In my local setup (using a docker-compose file, with Postgres in a separate container), when I run <code>rails db:setup</code>, I get the following error:</p>
  
  <pre><code>rails aborted!
  failed to execute:
  psql -q -f /rails/db/structure.sql cappy_dev
  
  Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions.
  
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/postgresql_database_tasks.rb:99:in `run_cmd'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/postgresql_database_tasks.rb:71:in `structure_load'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:213:in `structure_load'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:226:in `load_schema'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:253:in `block in load_schema_current'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:292:in `block in each_current_configuration'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:291:in `each'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:291:in `each_current_configuration'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/tasks/database_tasks.rb:252:in `load_schema_current'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/railties/databases.rake:306:in `block (3 levels) in &lt;top (required)&gt;'
  /usr/local/bundle/gems/activerecord-5.0.2/lib/active_record/railties/databases.rake:310:in `block (3 levels) in &lt;top (required)&gt;'
  /usr/local/bundle/gems/railties-5.0.2/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
  /usr/local/bundle/gems/railties-5.0.2/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
  /usr/local/bundle/gems/railties-5.0.2/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
  /usr/local/bundle/gems/railties-5.0.2/lib/rails/commands.rb:18:in `&lt;top (required)&gt;'
  bin/rails:9:in `require'
  bin/rails:9:in `&lt;main&gt;'
  Tasks: TOP =&gt; db:structure:load
  (See full trace by running task with --trace)
  </code></pre>
  
  <p>This makes sense because my Rails container only has Ruby and Rails-related tools, and does not have Postgres or pqsl, which are in the Postgres container.</p>
  
  <p>How do I run <code>rails db:setup</code> (or <code>db:migrate</code> or other tasks) if I don't have psql, pg_dump, and other Postgres tools in my Rails container?</p>
  
  <p><strong>UPDATE:</strong> Here is my docker-compose file:</p>
  
  <pre><code>version: '3'
  services:
    postgres:
      image: postgres:9.6
      volumes:
        - cappy-data:/var/lib/postgresql/data
      ports:
        - '5432:5432'
      environment:
        POSTGRES_PASSWORD: postgres
  
    cappy:
      image: REDACTED.dkr.ecr.us-east-1.amazonaws.com/cappy:latest
      build:
        context: .
      command: rails s -p 3000 -b '0.0.0.0'
      depends_on:
        - postgres
      volumes:
        - .:/rails
      ports:
        - "3000:3000"
      links:
        - "postgres:postgres"
      environment:
        RAILS_ENV: development
  
  volumes:
    cappy-data:
  </code></pre>
  
  <p>I don't think this file is the problem though--<code>db:setup</code> can create the database, it just can't load the <code>structure.sql</code> because it can't seem to find <code>psql</code>.</p>