I'm developing with containers and using docker-compose to lift them up.
From time to time I'll run docker-compose down
and will rebuild the containers. Most of the times I get this error
PG::ConnectionBad (could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
):
I don't get why Rails is complaining about Postgres not being there, if the entire containers are being rebuilt again. Also, the error just disappears after a while, without me doing anything other stopping, re-upping or rebuilding the containers. I moved over to developing with containers to precisely escape from annoying issues like this.
This are the contents of my docker-compose.yml
version: '2'
services:
users:
build:
context: '.'
links:
- postgres
- redis
volumes:
- ".:/app/users/"
working_dir: /app/users
command: [rails, server, -p, "3000", -b, 0.0.0.0]
ports:
- "3000:3000"
postgres:
image: postgres:9.5
environment:
POSTGRES_DB: somedb
POSTGRES_USER: someuser
POSTGRES_PASSWORD: somepass
redis:
image: redis:latest
command: redis-server
ports:
- "6379:6379"
volumes:
- "redis:/var/lib/redis/data"
volumes:
redis:
database.yml
development:
<<: *default
database: somedb
user: someuser
password: somepass
host: postgres
port: 5432
Am I missing extra configurations on the postgres service or is it related to the users container?
Add in docker-compose.yml users
version: '2'
services:
users:
environment:
DATABASE_URL:postgres://user:pass@postgres:5432/datex_dev?pool=5&encoding=utf-8
....
Add in database.yml
development:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
...
See Docker - PG::ConnectionBad
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With