I would like to run the postgres on a different port from my local machine pointing to 5432 in docker container.
version: '3'
services:
db:
image: postgres:alpine
restart: always
volumes:
- ./tmp/db:/var/lib/postgresql/data
ports:
- "9000:5432"
web:
build: .
restart: always
command: bash -c "rm -f tmp/pids/server.pid && rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3002:3000"
depends_on:
- db
and in database.yml I'm pointing the development environment to port 9000
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
host: db
username: postgres
database: myapp_development
port: 9000
test:
<<: *default
database: myapp_test
But when I run the rails app in localhost:3002 I'm getting
Could not connect to server: Connection refused Is the server running on host "db" (172.21.0.2) and accepting TCP/IP connections on port 9000?