简体   繁体   English

使用 PhpStorm 连接到 Postgres 容器

[英]Connect to Postgres container with PhpStorm

I would like to access my Postgres database (docker container) from PhpStorm.我想从 PhpStorm 访问我的 Postgres 数据库(docker 容器)。

docker-compose.yml docker-compose.yml

# Run docker-compose build
# Run docker-compose up
# Live long and prosper

version: '3.1'
services:
  apache:
    build: .docker/apache
    container_name: sf-apache
    ports:
      - 82:80
    volumes:
      - .docker/config/vhosts:/etc/apache2/sites-enabled
      - ${SYMFONY_APP}:/home/wwwroot/sf3
    depends_on:
      - php

  postgres:
    container_name: postgres
    restart: always
    image: 'postgres:12.6'
    ports:
      - "5432:5432"
    environment:
      - "POSTGRES_USER=${PGSQL_ADMIN_USER}"
      - "POSTGRES_PASSWORD=${PGSQL_ADMIN_PASSWORD}"
    volumes:
      - ./API/var/postgres:/var/lib/postgresql/data
      - .docker/postgresql/init-database.sh:/docker-entrypoint-initdb.d/init-database.sh

My PhpStorm config :我的 PhpStorm 配置: 在此处输入图片说明

I can access to my database via docker exec -it postgres bash我可以通过docker exec -it postgres bash访问我的数据库

If php storm is on the same host then you need to use localhost .如果 phpstorm 在同一台主机上,那么你需要使用localhost If both phpstorm and pg is part of the same compose file , then you would use the service name since both would be in the same virtual network如果 phpstorm 和 pg 是同一个 compose 文件的一部分,那么您将使用服务名称,因为它们都在同一个虚拟网络中。

I found the solution.我找到了解决方案。

I have a Postgres local and a Postgres with docker.我有一个本地的 Postgres 和一个带有 docker 的 Postgres。 My Postgres local get the upper hand on my docker Postgres.我的 Postgres 本地在我的 docker Postgres 上占了上风。 I have killed the service and put the container service name on it.我已经终止了该服务并将容器服务名称放在上面。

Works perfectly.完美运行。

Thanks for you help,谢谢你的帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM