簡體   English   中英

為什么導軌連接在 docker-compose 中不起作用?

[英]Why are rails connections not working in docker-compose?

我設置了一個非常基本的 rails 應用程序,它連接到一個 postgres 實例和一個 rails 實例。 出於某種原因,當我執行rails db:setup時,它不會連接到數據庫。 我的設置如下。 不要認為它可以變得更簡單。

需要注意的是,postgres 已啟動並准備好接受連接。

docker-compose.yml

version: '3.4'

services:
  postgres:
    image: postgres
    environment:
      - POSTGRES_PASSWORD=password
    volumes:
      - ./tmp/postgres/data:/var/lib/postgres/data
  redis:
    image: redis
    ports:
      - '6379:6379'
  web:
    build:
      context: .
      target: development
    command: tail -f /dev/null # I exec'ed in to run command
    depends_on:
      - postgres
      - redis
    env_file:
      - ./docker-dev.env
    ports:
      - '3000:3000'

數據庫.yml


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

錯誤輸出

D, [2020-04-03T03:20:34.562188 #32] DEBUG -- : using default configuration
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?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
Couldn't create 'hinge_test_db' database. Please check your configuration.
rails aborted!
PG::ConnectionBad: 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?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?

該錯誤與 docker 無關,但與 postgres 相關,打開 postgres 配置文件 pg_hba.conf 並將其設置為允許來自 localhost 的權限並重新啟動 postgres 服務器。 希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM