title: docker-compose with multiple postgres databases from sql dumps
body: <p>I know this may seem like a duplicate of <a href="https://stackoverflow.com/questions/39204142/docker-compose-with-multiple-databases">docker-compose with multiple databases</a>, but I still can't manage to get it working after going through the answers.</p>
  
  <p>Here is my <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3'
  services:
    backend:
      image: backend:1.0
      build: ./backend
      ports:
        - "9090:9090"
      depends_on:
        - db
        - ppt
      environment:
        - DATABASE_HOST=db
    db:
      image: main_db:26.03.18
      restart: always
      build: ./db
      ports:
        - "5432:5432"
    ppt:
      image: ppt_generator:1.0
      build: ./ppt
      ports:
        - "6060:6060"
    login:
      image: login:1.0
      build: ./login
      ports:
        - "7070:7070"
      depends_on:
        - login_db
    login_db:
      image: login_db:27.04.2018
      restart: always
      build: ./login_db
      ports:
        - "5433:5433"
  </code></pre>
  
  <p>Notice that I have one db on port 5433 and the other on 5432. However, when I run <code>docker ps</code> after starting the containers I get the following. I don't fully understand what is going on with the ports.</p>
  
  <pre><code>CONTAINER ID        IMAGE                 COMMAND                  CREATED              STATUS              PORTS                              NAMES
  997f816ddff3        backend:1.0           "/bin/sh -c 'pytho..."   About a minute ago   Up About a minute   0.0.0.0:9090-&gt;9090/tcp             backendservices_backend_1
  759546109a66        login:1.0             "/bin/sh -c 'pytho..."   About a minute ago   Up About a minute   0.0.0.0:7070-&gt;7070/tcp, 9090/tcp   backendservices_login_1
  a2a26b72dd0c        login_db:27.04.2018   "docker-entrypoint..."   About a minute ago   Up About a minute   5432/tcp, 0.0.0.0:5433-&gt;5433/tcp   backendservices_login_db_1
  3f97de7fc41e        main_db:26.03.18   "docker-entrypoint..."   About a minute ago   Up About a minute   0.0.0.0:5432-&gt;5432/tcp             backendservices_db_1
  1a61e741ccba        ppt_generator:1.0     "/bin/sh -c 'pytho..."   About a minute ago   Up About a minute   0.0.0.0:6060-&gt;6060/tcp             backendservices_ppt_1
  </code></pre>
  
  <p>Both my db dockerfiles are essentially identical except for the port number I expose:</p>
  
  <pre><code>FROM postgres:9.6.3
  ENV POSTGRES_USER ludo
  ENV POSTGRES_PASSWORD password
  ENV POSTGRES_DB login
  EXPOSE 5433
  
  ADD db_dump.sql /docker-entrypoint-initdb.d
  </code></pre>
  
  <p>This is the error I get:</p>
  
  <pre><code>backend_1   | Traceback (most recent call last):
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2147, in _wrap_pool_connect
  backend_1   |     return fn()
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 387, in connect
  backend_1   |     return _ConnectionFairy._checkout(self)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 766, in _checkout
  backend_1   |     fairy = _ConnectionRecord.checkout(pool)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 516, in checkout
  backend_1   |     rec = pool._do_get()
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1138, in _do_get
  backend_1   |     self._dec_overflow()
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
  backend_1   |     compat.reraise(exc_type, exc_value, exc_tb)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 187, in reraise
  backend_1   |     raise value
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1135, in _do_get
  backend_1   |     return self._create_connection()
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 333, in _create_connection
  backend_1   |     return _ConnectionRecord(self)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 461, in __init__
  backend_1   |     self.__connect(first_connect_check=True)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 651, in __connect
  backend_1   |     connection = pool._invoke_creator(self)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 105, in connect
  backend_1   |     return dialect.connect(*cargs, **cparams)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 393, in connect
  backend_1   |     return self.dbapi.connect(*cargs, **cparams)
  backend_1   |   File "/usr/local/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
  backend_1   |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
  backend_1   | psycopg2.OperationalError: could not connect to server: Connection refused
  backend_1   |   Is the server running on host "localhost" (127.0.0.1) and accepting
  backend_1   |   TCP/IP connections on port 5432?
  backend_1   | could not connect to server: Cannot assign requested address
  backend_1   |   Is the server running on host "localhost" (::1) and accepting
  backend_1   |   TCP/IP connections on port 5432?
  backend_1   | 
  </code></pre>
  
  <p>Why is the db not running on port 5432? It used to work when I only had one database and now with two it seems to be confused...?</p>
  
  <p><strong>UPDATE</strong>
  I can access the databases respectively on ports 5432 and 5433 locally. However, from my backend container I can't. My backend container seems to not be receiving anything running on port 5432. How do I make db container port 5432 visible to the backend container?</p>