无法从docker-compose postgresql服务连接到Postico

时间:2018-07-25 02:39:27

标签: postgresql docker docker-compose

我已经完成了docker-compose,并且能够运行附加到postgresql映像的Web服务。问题是,当我尝试访问数据库时,无法在postico上查看数据。图像的名称是db,当我尝试在连接之前在postico上将主机名指定为“ db”时,出现错误消息,提示未找到主机名。我已经在docker-compose文件中键入凭据,端口和数据库名称的方式相同。

有人知道我如何找到在容器内连接的正确设置吗?

version: '3.6'
services:
  phoenix:
    # tell docker-compose which Dockerfile it needs to build
    build:
      context: .
      dockerfile: Dockerfile.phoenix.development
    # map the port of phoenix to the local dev port
    ports:
      - 4000:4000
    # mount the code folder inside the running container for easy development
    volumes:
      - ./my_app:/app
    # make sure we start mongodb when we start this service
    # links:
    #   - db
    depends_on:
      - db
      - redis
    environment:
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      FACEBOOK_CLIENT_ID: ${FACEBOOK_CLIENT_ID}
      FACEBOOK_CLIENT_SECRET: ${FACEBOOK_CLIENT_SECRET}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
  go:
    build:
      context: .
      dockerfile: Dockerfile.go.development
    ports:
      - 8080:8080
    volumes:
      - ./genesys-api:/go/src/github.com/sc4224/genesys-api
    depends_on:
      - db
      - redis
      - phoenix
  db:
    container_name: db
    image: postgres:latest
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
    volumes:
      - ./data/db:/data/db
    restart: always
  redis:
    container_name: redis
    image: redis:latest
    ports:
      - "6379:6379"
    volumes:
      - ./data/redis:/data/redis
    entrypoint: redis-server
    restart: always

1 个答案:

答案 0 :(得分:0)

使用主机名作为localhost

您不能在内部docker网络外部使用主机名db。这将在同一网络中运行的应用程序中工作。 由于您公开了该数据库以在端口5432上运行,因此它是通过0.0.0.0:5432->5432/tcp公开的,因此可以用localhost作为主机和端口5432

进行访问。