title: Error: pg_config executable not found when installing psycopg2 on Alpine in Docker
body: <p>I'm trying to build a Flask app using Postgres with Docker. I'd like to connect to an AWS RDS instance of Postgres, but use Docker for my Flask app. However, when trying to set up <code>psycopg2</code> it runs into an error because it can't find <code>pg_config</code>. Here's the error:</p>
  <pre><code>Building api
  Step 1/5 : FROM python:3.6.3-alpine3.6
   ---&gt; 84c98ca3b5c5
  Step 2/5 : WORKDIR /usr/src/app
   ---&gt; Using cache
   ---&gt; 407c158f5ee4
  Step 3/5 : COPY . .
   ---&gt; 966df18d329e
  Step 4/5 : RUN pip install -r requirements.txt
   ---&gt; Running in 284cc97aeb63
  Collecting aniso8601==1.3.0 (from -r requirements.txt (line 1))
    Downloading aniso8601-1.3.0.tar.gz (57kB)
  Collecting click==6.7 (from -r requirements.txt (line 2))
    Downloading click-6.7-py2.py3-none-any.whl (71kB)
  Collecting Flask==0.12.2 (from -r requirements.txt (line 3))
    Downloading Flask-0.12.2-py2.py3-none-any.whl (83kB)
  Collecting Flask-RESTful==0.3.6 (from -r requirements.txt (line 4))
    Downloading Flask_RESTful-0.3.6-py2.py3-none-any.whl
  Collecting Flask-SQLAlchemy==2.3.2 (from -r requirements.txt (line 5))
    Downloading Flask_SQLAlchemy-2.3.2-py2.py3-none-any.whl
  Collecting itsdangerous==0.24 (from -r requirements.txt (line 6))
    Downloading itsdangerous-0.24.tar.gz (46kB)
  Collecting Jinja2==2.9.6 (from -r requirements.txt (line 7))
    Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB)
  Collecting MarkupSafe==1.0 (from -r requirements.txt (line 8))
    Downloading MarkupSafe-1.0.tar.gz
  Collecting psycopg2==2.7.3.1 (from -r requirements.txt (line 9))
    Downloading psycopg2-2.7.3.1.tar.gz (425kB)
      Complete output from command python setup.py egg_info:
      running egg_info
      creating pip-egg-info/psycopg2.egg-info
      writing pip-egg-info/psycopg2.egg-info/PKG-INFO
      writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
      writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
      writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
      Error: pg_config executable not found.
  
      Please add the directory containing pg_config to the PATH
      or specify the full executable path with the option:
  
          python setup.py build_ext --pg-config /path/to/pg_config build ...
  
      or with the pg_config option in 'setup.cfg'.
  
      ----------------------------------------
  Command &quot;python setup.py egg_info&quot; failed with error code 1 in /tmp/pip-build-01lf5grh/psycopg2/
  ERROR: Service 'api' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
  </code></pre>
  <p>Here's my <code>Dockerfile</code>:</p>
  <pre><code>FROM python:3.6.3-alpine3.6
  
  WORKDIR /usr/src/app
  
  COPY . .
  
  RUN pip install -r requirements.txt
  
  CMD [&quot;python&quot;, &quot;app.py&quot;]
  </code></pre>
  <p><strong>Many others seem to have a similar issue locally, but none of them involve using Docker. This seems like a Docker issue because I can set up a local virtual environment and the setup works just fine since I have Postgres installed locally and it's able to find my local <code>pg_config</code>.</strong></p>
  <p>It appears that during the container build/setup, Docker is trying to find <code>pg_config</code> within the container. Is there a way to install a <code>pg_config</code> in the container, even though I won't be using a containerized instance of Postgres, but rather the instance on RDS?</p>
  <p>Any and all suggestions on how to get around this are welcomed.</p>