我一直在关注如何使用Docker:
Setting Up A Rails Development Environment Using Docker设置Rails开发环境的指南.
我一路上遇到了一些障碍,但是我已经成功地完成了大部分工作,直到运行Rails迁移的步骤.运行命令docker-compose run web rake db:migrate会产生以下结果:
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?
泊坞窗,compose.yml:
version: '2' services: db: image: postgres volumes: - ./pgdata:/pgdata environment: POSTGRES_DB: myapp_development POSTGRES_USER: postgres POSTGRES_PASSWORD: PGDATA: /pgdata web: build: . command: bundle exec rails server --port 5000 --binding 0.0.0.0 volumes_from: - container:myapp-web-sync:rw - container:myapp-bundle-sync:rw volumes: - ./keys:/root/.ssh/ ports: - "5000:5000" environment: REdis_URL: redis://redis:6379 GEM_HOME: /bundle links: - db - redis volumes: myapp-web-sync: external: true myapp-bundle-sync: external: true
解决方法
您尝试连接到localhost:5432,换句话说,您尝试连接到Web容器,但您的观点是db.只需在应用程序中指定数据库主机,如db
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。