社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  docker

docker compose-无法连接到postgres db

user1298426 • 3 年前 • 1190 次点击  

我试图在Jenkins slave上运行docker compose命令,但在运行命令pytest tests/integration时失败。 该命令使用后端作为postgres运行集成测试。 Dockerfile是

version: "3.4"
services:
  test:
    build:
      context: ../..
      dockerfile: Dockerfile
    depends_on:
      - postgres_db
    environment:
      PG_UNITTEST_DB: "postgresql://testuser:testpassword@postgres_db/testdb"
    command: pytest tests/integration
  postgres_db:
    image:  postgis/postgis
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: testpassword
      POSTGRES_USER: testuser
      POSTGRES_DB: testdb

我得到的错误是

psycopg2.OperationalError: could not connect to server: Connection refused
 Is the server running on host "postgres_db" (172.19.0.2) and accepting
 TCP/IP connections on port 5432?

我试图在postgres_db部分的docker compose文件中公开5432端口,但没有帮助。同样的代码在本地运行良好。我运行的命令是

docker-compose -f tests/integration/docker-compose.yml up --build --exit-code-from test
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133273
 
1190 次点击  
文章 [ 2 ]  |  最新文章 3 年前