title: docker springboot only connects on postgres 5432 via docker-compose
body: <p>Using docker to connect springboot to postgres via docker-compose.  Using port 5432 on postgres works fine, if i try an port other than that it fails</p>
  
  <p><strong>working code</strong></p>
  
  <p>spring</p>
  
  <pre><code>spring.datasource.url=jdbc:postgresql://db:5432/wwc
  spring.datasource.username=wwc
  spring.datasource.password=test
  spring.datasource.driver-class-name=org.postgresql.Driver
  </code></pre>
  
  <p>docker-compose</p>
  
  <pre><code>version: '2.1'
  services:
    db:
      container_name: db
      image: postgres:9.4
      ports:
        - 5432:5432
      volumes:
        - /tmp:/var/lib/postgresql
      environment:
        - POSTGRES_USER=wwc
        - POSTGRES_DB=wwc
        - POSTGRES_PASSWORD=test
    server:
      container_name: spring-boot-rest-server
      build:
        context: .
        dockerfile: Dockerfile.server
      ports:
        - 8080:8080
      logging:
        driver: json-file
      depends_on:
        - db
  
    web:
      container_name: nginx-web
      links:
        - "server:springboot"
      build:
        context: .
        dockerfile: Dockerfile.web
      ports:
        - 80:80
        - 8088:8088
      logging:
        driver: json-file
      depends_on:
        - server
  </code></pre>
  
  <p>**connection refused code **</p>
  
  <p>spring</p>
  
  <pre><code>spring.datasource.url=jdbc:postgresql://db:6000/wwc
  spring.datasource.username=wwc
  spring.datasource.password=test
  spring.datasource.driver-class-name=org.postgresql.Driver
  </code></pre>
  
  <p>docker-compose</p>
  
  <pre><code>version: '2.1'
  services:
    db:
      container_name: db
      image: postgres:9.4
      ports:
        - 6000:5432
      volumes:
        - /tmp:/var/lib/postgresql
      environment:
        - POSTGRES_USER=wwc
        - POSTGRES_DB=wwc
        - POSTGRES_PASSWORD=test
    server:
      container_name: spring-boot-rest-server
      build:
        context: .
        dockerfile: Dockerfile.server
      ports:
        - 8080:8080
      logging:
        driver: json-file
      depends_on:
        - db
  
    web:
      container_name: nginx-web
      links:
        - "server:springboot"
      build:
        context: .
        dockerfile: Dockerfile.web
      ports:
        - 80:80
        - 8088:8088
      logging:
        driver: json-file
      depends_on:
        - server
  </code></pre>
  
  <p><strong>error:</strong></p>
  
  <p>spring-boot-rest-server | org.postgresql.util.PSQLException: Connection to db:6000 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.</p>
  
  <p>What am i doing wrong?</p>