IIC2143-2019-2/proyecto

[proyecto][macOS] - Error: FATAL: database "rails_development" does not exist

dmelberg opened this issue · 6 comments

Hola, segui los pasos para correr una app ya creada en mi pc. Hice
docker-compose run web rails db:create
Pero al meterme a localhost me muestra esto:
image

Hola! Podrías mandar el output del comando docker-compose run web rails db:create?

Deborahs-MacBook-Pro:example deborahelberg$ docker-compose run web rails db:create
Starting example_db_1 ... done
could not connect to server: Connection refused
	Is the server running on host "db" (172.20.0.2) and accepting
	TCP/IP connections on port 5432?
Couldn't create 'rails_development' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: could not connect to server: Connection refused
	Is the server running on host "db" (172.20.0.2) and accepting
	TCP/IP connections on port 5432?
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:692:in `connect'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/postgresql_database_tasks.rb:21:in `create'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:119:in `create'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:139:in `block in create_current'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:316:in `block in each_current_configuration'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:313:in `each'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:313:in `each_current_configuration'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/tasks/database_tasks.rb:138:in `create_current'
/usr/local/bundle/gems/activerecord-5.2.3/lib/active_record/railties/databases.rake:29:in `block (2 levels) in <main>'
/usr/local/bundle/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:23:in `block in perform'
/usr/local/bundle/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
/example/bin/rails:9:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/example/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:create
(See full trace by running task with --trace)
Deborahs-MacBook-Pro:example deborahelberg$ docker-compose up
Recreating example_db_1 ... done
Recreating example_web_1 ... done
Attaching to example_db_1, example_web_1
db_1   | The files belonging to this database system will be owned by user "postgres".
db_1   | This user must also own the server process.
db_1   | 
db_1   | The database cluster will be initialized with locale "en_US.utf8".
db_1   | The default database encoding has accordingly been set to "UTF8".
db_1   | The default text search configuration will be set to "english".
db_1   | 
db_1   | Data page checksums are disabled.
db_1   | 
db_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1   | creating subdirectories ... ok
db_1   | selecting default max_connections ... 100
db_1   | selecting default shared_buffers ... 128MB
db_1   | selecting default timezone ... Etc/UTC
db_1   | selecting dynamic shared memory implementation ... posix
db_1   | creating configuration files ... ok
db_1   | running bootstrap script ... ok
db_1   | performing post-bootstrap initialization ... ok
db_1   | syncing data to disk ... ok
db_1   | 
db_1   | Success. You can now start the database server using:
db_1   | 
db_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1   | 
db_1   | 
db_1   | WARNING: enabling "trust" authentication for local connections
db_1   | You can change this by editing pg_hba.conf or using the option -A, or
db_1   | --auth-local and --auth-host, the next time you run initdb.
db_1   | ****************************************************
db_1   | WARNING: No password has been set for the database.
db_1   |          This will allow anyone with access to the
db_1   |          Postgres port to access your database. In
db_1   |          Docker's default configuration, this is
db_1   |          effectively any other container on the same
db_1   |          system.
db_1   | 
db_1   |          Use "-e POSTGRES_PASSWORD=password" to set
db_1   |          it in "docker run".
db_1   | ****************************************************
db_1   | waiting for server to start....2019-09-14 20:11:36.149 UTC [44] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-09-14 20:11:36.207 UTC [45] LOG:  database system was shut down at 2019-09-14 20:11:33 UTC
db_1   | 2019-09-14 20:11:36.228 UTC [44] LOG:  database system is ready to accept connections
db_1   |  done
db_1   | server started
db_1   | 
db_1   | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1   | 
db_1   | waiting for server to shut down...2019-09-14 20:11:36.344 UTC [44] LOG:  received fast shutdown request
db_1   | .2019-09-14 20:11:36.347 UTC [44] LOG:  aborting any active transactions
db_1   | 2019-09-14 20:11:36.352 UTC [44] LOG:  background worker "logical replication launcher" (PID 51) exited with exit code 1
db_1   | 2019-09-14 20:11:36.352 UTC [46] LOG:  shutting down
db_1   | 2019-09-14 20:11:36.384 UTC [44] LOG:  database system is shut down
db_1   |  done
db_1   | server stopped
db_1   | 
db_1   | PostgreSQL init process complete; ready for start up.
db_1   | 
db_1   | 2019-09-14 20:11:36.487 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2019-09-14 20:11:36.487 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2019-09-14 20:11:36.490 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2019-09-14 20:11:36.549 UTC [53] LOG:  database system was shut down at 2019-09-14 20:11:36 UTC
db_1   | 2019-09-14 20:11:36.573 UTC [1] LOG:  database system is ready to accept connections
web_1  | => Booting Puma
web_1  | => Rails 5.2.3 application starting in development 
web_1  | => Run `rails server -h` for more startup options
web_1  | Puma starting in single mode...
web_1  | * Version 3.12.1 (ruby 2.6.0-p-1), codename: Llamas in Pajamas
web_1  | * Min threads: 5, max threads: 5
web_1  | * Environment: development
web_1  | * Listening on tcp://0.0.0.0:3000
web_1  | Use Ctrl-C to stop
web_1  | Started GET "/" for 172.20.0.1 at 2019-09-14 20:11:49 +0000
web_1  | Cannot render console from 172.20.0.1! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
db_1   | 2019-09-14 20:11:49.986 UTC [60] FATAL:  database "rails_development" does not exist
web_1  |   
web_1  | ActiveRecord::NoDatabaseError (FATAL:  database "rails_development" does not exist
web_1  | ):
web_1  |   
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/postgresql_adapter.rb:696:in `rescue in connect'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/postgresql_adapter.rb:691:in `connect'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/postgresql_adapter.rb:223:in `initialize'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `new'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/postgresql_adapter.rb:48:in `postgresql_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:811:in `new_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:855:in `checkout_new_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:834:in `try_to_checkout_new_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:795:in `acquire_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:523:in `checkout'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:1014:in `retrieve_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_handling.rb:118:in `retrieve_connection'
web_1  | activerecord (5.2.3) lib/active_record/connection_handling.rb:90:in `connection'
web_1  | activerecord (5.2.3) lib/active_record/migration.rb:554:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
web_1  | activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web_1  | web-console (3.7.0) lib/web_console/middleware.rb:135:in `call_app'
web_1  | web-console (3.7.0) lib/web_console/middleware.rb:22:in `block in call'
web_1  | web-console (3.7.0) lib/web_console/middleware.rb:20:in `catch'
web_1  | web-console (3.7.0) lib/web_console/middleware.rb:20:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web_1  | railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'
web_1  | railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'
web_1  | activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'
web_1  | activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'
web_1  | activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'
web_1  | railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'
web_1  | sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'
web_1  | rack (2.0.7) lib/rack/method_override.rb:22:in `call'
web_1  | rack (2.0.7) lib/rack/runtime.rb:22:in `call'
web_1  | activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1  | actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'
web_1  | rack (2.0.7) lib/rack/sendfile.rb:111:in `call'
web_1  | railties (5.2.3) lib/rails/engine.rb:524:in `call'
web_1  | puma (3.12.1) lib/puma/configuration.rb:227:in `call'
web_1  | puma (3.12.1) lib/puma/server.rb:660:in `handle_request'
web_1  | puma (3.12.1) lib/puma/server.rb:474:in `process_client'
web_1  | puma (3.12.1) lib/puma/server.rb:334:in `block in run'
web_1  | puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

Podrías mandarme el contenido de tu config/database.yml, tu docker-compose.yml y tu Dockerfile?

config/database.yml

  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password:
  pool: 5

development:
  <<: *default
  database: rails_development


test:
  <<: *default
  database: rails_test

docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/example
    ports:
      - "3000:3000"
    depends_on:
      - db

Dockerfile

FROM ruby:2.6-rc
RUN apt-get update &&\
    # add support to unicode chars from keyboard: ç,ã,ô:
    apt-get install -y locales &&\
    echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && /usr/sbin/locale-gen &&\
    rm -rf /var/lib/apt/lists/*
ENV LANG en_US.UTF-8
RUN apt-get update -qq && apt-get install -y postgresql-client
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
        && apt-get install -y nodejs

ENV APP_HOME /example

RUN mkdir $APP_HOME
WORKDIR $APP_HOME
COPY Gemfile $APP_HOME/Gemfile
COPY Gemfile.lock $APP_HOME/Gemfile.lock
RUN bundle install
COPY . $APP_HOME

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]

Mira, los valores para el nombre de tu app difieren entre tu Dockerfile, tu docker-compose.yml y tu config/database.yml. Te recomiendo homogeneizar los nombres de tu app, buildearla de nuevo e intentarlo nuevamente. Recuerda que también debes cambiar el nombre de la app en el entrypoint.sh.

arreglado, pense que lo tenia hecho y al parecer no, gracias!