服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接

服务器是否在主机“localhost”(::1) 上运行并接受端口 5432 上的 TCP/IP 连接

我正在尝试使用以下命令连接到 Ruby/Docker 容器内的 Postgres 数据库:

docker-compose run app rails db:setup

只有我的堆栈跟踪报告;-

Starting reptrax-uk_postgres_1 ... done
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 database for {"host"=>"localhost", "port"=>5432, "adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"development", "pool"=>10, "username"=>"user", "password"=>"secret"}
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?

所以我发出一个

netstat -antu | grep 5432

检查是否有与违规端口相关的任何内容,但什么也没有,它返回空白。

这是我的快照docker-compose.yml

version: '3'

services:
  app:
    build: .
    command: sh -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    environment:
      - RABBITMQ_HOST=rabbitmq
      - MONGO_HOST=mongo
      - POSTGRES_HOST=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASS=
    volumes:
      - .:/app
      - bundle:/bundle
      - node_modules:/app/node_modules
    ports:
      - "3000:3000"
    depends_on:
      - postgres
      - mongo
      - rabbitmq
      - redis
      - chrome
  postgres:
    image: postgres:9.5
    ports:
      - "5432:5432"
  mongo:
    image: mongo
    ports:

我昨天尝试了各种 docker 命令,包括;-

docker-compose stop
docker-compose down
docker system prune
docker pull postgres:9.5

但仍然没有喜悦。

你能排除故障吗?

答案1

为我工作;-

docker-compose.ymlpostgres 设置下添加以下条目;-

postgres:
    image: postgres:9.5
    environment:
      - POSTGRES_HOST_AUTH_METHOD=trust
    ports:
      - "5432:5432"

然后在终端 - 继续;-

docker-compose down
docker container stop $(docker container ls -aq)
docker network create x_middleware
docker network create foo
docker-compose build
docker-compose run app bin/rails db:setup profiles:build
docker-compose run app bin/rails profiles:build
docker-sync-stack start

相关内容