Changing a postgres containers server port in Docker Compose
<p>I am trying to deploy a second database container on a remote server using Docker compose. This postgresql server runs on port 5433 as opposed to 5432 as used by the first postgresql container.</p>
<p>When I set up the application I get this error output:</p>
<pre><code>web_1  | django.db.utils.OperationalError: could not connect to server: Connection refused
web_1  |    Is the server running on host &quot;db&quot; (172.17.0.2) and accepting
web_1  |    TCP/IP connections on port 5433?
</code></pre>
<p>and my docker compose file is:</p>
<pre class="lang-yaml prettyprint-override"><code>db:
  image: postgres:latest
  environment:
    POSTGRES_PASSWORD: route_admin
    POSTGRES_USER: route_admin
  expose:
    - &quot;5433&quot;
  ports:
    - &quot;5433&quot;
  volumes:
    - ./backups:/home/backups
   
web:
  build: .
  command:  bash -c &quot;sleep 5 &amp;&amp; python -u application/manage.py runserver 0.0.0.0:8081&quot;
  volumes:
    - .:/code
  ports:
    - &quot;81:8081&quot;
  links:
    - db
  environment:
    - PYTHONUNBUFFERED=0
</code></pre>
<p>I feel the issue must be the <code>postgresql.conf</code> file on the server instance having set the port to 5432 causing the error when my app tries to connect to it. Is there a simple way of changing the port using a command in the compose file as opposed to messing around with volumes to replace the file?</p>
<p>I am using the official postgresql container for this job.</p>