Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Connection refused when running rake assets:precompile with database service #9

Open
paulodiovani opened this issue Oct 21, 2015 · 4 comments

Comments

@paulodiovani
Copy link

The step rake assets:precompile tries to connect to database and, as on build the links wasn't set yet, the build fails with:

rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
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?

My docker-compose.yml looks like:

web:
  build: .
  command: 'bash -c ''bundle exec puma -C config/puma.rb'''
  working_dir: /app/user
  environment:
    PORT: 8080
    DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
    REDIS_URL: 'redis://herokuRedis:6379'
  ports:
    - '8080:8080'
  links:
    - herokuPostgresql
    - herokuRedis
worker:
  build: .
  command: 'bash -c ''bundle exec sidekiq -C config/sidekiq.yml'''
  working_dir: /app/user
  environment:
    DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
    REDIS_URL: 'redis://herokuRedis:6379'
  links:
    - herokuPostgresql
    - herokuRedis
shell:
  build: .
  command: bash
  working_dir: /app/user
  environment:
    PORT: 8080
    DATABASE_URL: 'postgres://postgres:@herokuPostgresql:5432/postgres'
    REDIS_URL: 'redis://herokuRedis:6379'
  ports:
    - '8080:8080'
  links:
    - herokuPostgresql
    - herokuRedis
  volumes:
    - '.:/app/user'
herokuPostgresql:
  image: postgres
herokuRedis:
  image: redis
@hxegon
Copy link

hxegon commented Mar 30, 2016

I have the same issue. Only thing that gets me past assets:precompile is copying the dockerfile and adding ONBUILD EXPOSE 5432 before the assets:precompile task. My dockerfile and docker-compose.yml were written by the heroku docker init command, and haven't been touched.

Can anyone else confirm this? Are there any objections to putting this in?

EDIT: Actually this is a different error. I submitted a new issue #15

@paulodiovani
Copy link
Author

@hxegon if your problem happens whe running docker build, I think it's the same problem.

@lynndylanhurley
Copy link

I'm having the same issue. Here's my stacktrace:
https://gist.github.com/lynndylanhurley/fe4584c6f94fffede1d069521ea3df5b

I just ran docker-compose web up on a new Rails project.

Here's my database.yml file:

# PostgreSQL. Versions 9.1 and up are supported.
default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  url: <%= ENV['DATABASE_URL'] %>
  timeout: 5000

development:
  <<: *default

test:
  <<: *default

production:
  <<: *default

@martinjego
Copy link

Here post this on your terminal. heroku addons:create heroku-postgresql

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants