다음 명령을 사용하여 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-compose stop
docker-compose down
docker system prune
docker pull postgres:9.5
그러나 여전히 기쁨은 없습니다.
문제를 해결할 수 있나요?
답변1
나를 위해 일합니다;-
postgres 설정 아래에 다음 항목을 추가하십시오 docker-compose.yml
.
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