5

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?

2
  • Did you solve this ever? Commented May 10, 2017 at 21:31
  • @creimers not exactly. See accepted answer. Commented May 11, 2017 at 18:38

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

For the record, and sadly, the problem went away when downing the containers and building them again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.