title: In testing.postgresql, cannot find initdb command inside Docker
body: <p>There is a <a href="https://stackoverflow.com/questions/57720546/testing-postgresql-command-not-found-initdb-inside-docker">similar thread</a> that has the same problem but wasn't able to work for me. Basically, I'm trying to unittest <code>myproject</code> with <code>testing.postgresql</code> and i'm running it inside a docker container.</p>
  
  <p>However, I get a <code>RuntimeError: command not found: initdb</code> when I run my command,</p>
  
  <p><code>docker-compose exec myproject python3 -m unittest</code></p>
  
  <p>This works in WSL but not inside docker. </p>
  
  <p>Looks like it's not able to find initdb. Is it having conflict issues with the database created in docker-compose.yml or am I missing some lines inside the docker files?</p>
  
  <p>I outline my test like example from the <a href="https://pypi.org/project/testing.postgresql/" rel="nofollow noreferrer">docs</a>: </p>
  
  <pre><code>class TestPostgresqlInteraction(unittest.TestCase):
  
      Postgresql = testing.postgresql.PostgresqlFactory(cache_initialized_db=True)
  
      with testing.postgresql.Postgresql() as postgresql:
          engine = create_engine(postgresql.url())
          dbConn = psycopg2.connect(**postgresql.dsn())
          cursor = dbConn.cursor()
          def setUp(self):
              self.postgresql = self.Postgresql()
  
          def tearDown(self):
              self.postgresql.stop()
  
          def testMethod(self)
              conn = psycopg2.connect(**self.postgresql.dsn())
              cursor = conn.cursor()
              # execute cursor and do tests... 
  
          def tearDownModule(self):
              self.Postgresql.clear_cache()
  </code></pre>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: "3"
  services:
      myproject:
          build:
              context: .
              dockerfile: ./myproject/Dockerfile
          depends_on:
              - database
          volumes:
              - ./myproject:/code
          stdin_open: true
          tty: true
      database:
          build:
              context: .
              dockerfile: ./database/Dockerfile
          environment:
              POSTGRES_USER_FILE: /secrets/dbUser.txt
              POSTGRES_PASSWORD_FILE: /secrets/dbPassword.txt
          ports:
              - "8765:5432"
          volumes:
              - otherdata:/var/lib/postgresql/data
  </code></pre>
  
  <p>myproject/Dockerfile</p>
  
  <pre><code>FROM python:3.7.3-stretch
  
  RUN apt-get update &amp;&amp; apt-get install -y \
      poppler-utils
  
  ARG moduleDir=myproject
  
  WORKDIR /code
  
  COPY secrets/ /secrets
  
  # COPY $moduleDir/myproject/ ./
  
  COPY $moduleDir/requirements.txt requirements.txt
  
  RUN pip install -r requirements.txt
  </code></pre>
  
  <p>database/Dockerfile</p>
  
  <pre><code>FROM postgres:11.3
  
  WORKDIR /secrets
  
  COPY secrets/dbUser.txt dbUser.txt
  COPY secrets/dbPassword.txt dbPassword.txt
  
  RUN mkdir -p /docker-entrypoint-initdb.d
  
  COPY database/schema.sql /docker-entrypoint-initdb.d
  </code></pre>
  
  <p>Traceback:</p>
  
  <pre><code>ImportError: Failed to import test module: tests.testMyproject
    File "/usr/local/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
      module = self._get_module_from_name(name)
    File "/usr/local/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
      __import__(name)
    File "/code/tests/testmyProject.py", line 40, in &lt;module&gt;
      class TestPostgresqlInteraction(unittest.TestCase):
    File "/code/tests/testmyProject.py", line 46, in TestPostgresqlInteraction
      Postgresql = testing.postgresql.PostgresqlFactory(cache_initialized_db=True)
    File "/usr/local/lib/python3.7/site-packages/testing/common/database.py", line 52, in __init__
      self.cache = self.target_class(**settings_noautostart)
    File "/usr/local/lib/python3.7/site-packages/testing/common/database.py", line 92, in __init__
      self.initialize()
    File "/usr/local/lib/python3.7/site-packages/testing/postgresql.py", line 50, in initialize
      self.initdb = find_program('initdb', ['bin'])
    File "/usr/local/lib/python3.7/site-packages/testing/postgresql.py", line 144, in find_program
      raise RuntimeError("command not found: %s" % name)
  RuntimeError: command not found: initdb
  </code></pre>