Im trying to connect to a Postgres database within a Ruby/Docker container with;
docker-compose run app rails db:setup
only my stack trace reports;-
Starting reptrax-uk_postgres_1 ... done
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Couldn't create database for {"host"=>"localhost", "port"=>5432, "adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"development", "pool"=>10, "username"=>"user", "password"=>"secret"}
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
So I issue a
netstat -antu | grep 5432
to check for anything relating to the offending port but nothing, it returns blank.
Here's a snapshot of my docker-compose.yml
version: '3'
services:
app:
build: .
command: sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
environment:
- RABBITMQ_HOST=rabbitmq
- MONGO_HOST=mongo
- POSTGRES_HOST=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASS=
volumes:
- .:/app
- bundle:/bundle
- node_modules:/app/node_modules
ports:
- "3000:3000"
depends_on:
- postgres
- mongo
- rabbitmq
- redis
- chrome
postgres:
image: postgres:9.5
ports:
- "5432:5432"
mongo:
image: mongo
ports:
I tried a whole manner of docker commands yesterday including;-
docker-compose stop
docker-compose down
docker system prune
docker pull postgres:9.5
but still no joy.
Are you able to troubleshoot?