title: How to specify different port for a Docker postgres instance?
body: <p>I am trying to get a postgres container running on a different port (5433 instead of the default 5432) per several online threads like this one:
  <a href="https://github.com/docker-library/postgres/issues/196#issuecomment-310209118" rel="noreferrer">https://github.com/docker-library/postgres/issues/196#issuecomment-310209118</a></p>
  
  <p>(The reason for the port change is because an unrelated project that I leave running is already using port 5432 so I'd like to be able to run rspec simultaneously on multiple projects.)</p>
  
  <p>In my test ENV I have 
  DATABASE_URL=postgresql://postgres:@db.local:5433/test_agile_self</p>
  
  <p>Everything worked when I was using port 5432 (in DATABASE_URL and docker-compose.yml)</p>
  
  <p>After changing the port to 5433, when I run rspec I get:</p>
  
  <pre><code>PG::ConnectionBad:
    could not connect to server: Connection refused
      Is the server running on host "db.local" (172.22.0.2) and accepting
      TCP/IP connections on port 5433?
  # ./spec/spec_helper.rb:62:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>The container does indeed seem to be running on port 5433 and IP address 172.22.0.2:</p>
  
  <pre><code>$ docker ps
  CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
  a8f5dee227e8        postgres:10.5       "docker-entrypoint.s…"   27 minutes ago      Up 14 seconds       0.0.0.0:5433-&gt;5432/tcp   zarc_db.local_1
  </code></pre>
  
  <pre><code>$ docker inspect a8f5dee227e8 | grep "IPAddress"
              "SecondaryIPAddresses": null,
              "IPAddress": "",
                      "IPAddress": "172.22.0.2",
  </code></pre>
  
  <p>My docker-compose.yml uses the <code>ports: "5433:5432"</code> as per the discussion linked above.</p>
  
  <pre><code>#docker-compose.yml
  version: '3'
  services:
    web:
      build: .
      ports:
        - "3010:3010"
      volumes:
        - .:/my_app
      links:
        - db.local
      depends_on:
        - db.local
  
    db.local:
      image: postgres:10.5
      ports:
        - "5433:5432"
  </code></pre>
  
  <p>If I change 5433 back to 5432 in those two spots (ENV and docker-compose.yml) it works again.</p>
  
  <p>This is on a Mac running Mohave 10.14.3, and Docker 18.09.2</p>