使用docker-compose编排容器时,如容器之间须要互相通讯,使用本地链接,须要使用容器名来代替localhostweb
"connection": "postgresql+psycopg2://postgres:123456@localhost/database"
链接串中的localhost须要替换成postgresql容器名sql
version: '3' services: db: build: ./db environment: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=123456 - POSTGRES_DB=database volumes: - ./db/init:/docker-entrypoint-initdb.d/ container_name: db restart: always ports: - "5432:5432" web: build: ./web restart: always volumes: - ./web/codes:/code ports: - "80:8080" links: - db depends_on: - db container_name: web
即docker
"connection": "postgresql+psycopg2://postgres:123456@db/database"