如何在Docker中链接PostgreSQL容器和PgAdmin?

ryoqjall  于 2023-04-05  发布在  Docker
关注(0)|答案(2)|浏览(169)

我在Laravel项目中有一个带有postgres和pgadmin服务的docker-compose文件。问题是,当我进行数据库迁移时,它成功了,但当我转到pgadmin时,我看不到我在那里创建的表。我想我和往常一样,在编写docker-compose时犯了一个错误,我只是找不到我缺少的东西。

version: '3'
services:
#PHP Service
app:
    build:
        context: .
        dockerfile: Dockerfile
    image: digitalocean.com/php
    container_name: app
    restart: unless-stopped
    tty: true
    environment:
        SERVICE_NAME: app
        SERVICE_TAGS: dev
    working_dir: /var/www
    volumes:
        - ./:/var/www
        - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
        - postgres
#Nginx Service
webserver:
    image: nginx:alpine
    container_name: webserver
    restart: unless-stopped
    tty: true
    ports:
        - "80:80"
        - "443:443"
    volumes:
        - ./:/var/www
        - ./docker/nginx/conf.d/:/etc/nginx/conf.d/
    networks:
        - postgres
#Redis
redis:
    image: 'redis:alpine'
    ports:
        - "6379:6379"
#PostgreSQL        
postgres:
    container_name: postgres_container
    image: postgres
    environment:
        POSTGRES_DB: postgres
        POSTGRES_USER: postgres
        POSTGRES_PASSWORD: secret
        PGDATA: /data/postgres
    volumes:
        - postgres:/data/postgres
    ports:
        - "5432:5432"
    networks:
        - postgres
    restart: unless-stopped

pgadmin:
    container_name: pgadmin_container
    image: dpage/pgadmin4
    environment:
        PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org}
        PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
    volumes:
        - pgadmin:/root/.pgadmin
    ports:
        - "${PGADMIN_PORT:-5050}:80"
    networks:
        - postgres
    restart: unless-stopped        
#RabbitMQ
rabbit:
    image: "rabbitmq:3-management"
    hostname: "rabbit"
    environment:
        RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
        RABBITMQ_DEFAULT_USER: "rabbitmq"
        RABBITMQ_DEFAULT_PASS: "rabbitmq"
        RABBITMQ_DEFAULT_VHOST: "/"
    ports:
        - "15672:15672"
        - "5672:5672"
    labels:
        NAME: "rabbitmq"  
#ElasticSearch
elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
    ports:
        - "9200:9200"
        - "9300:9300"
    networks:
        - postgres

Docker Networks网络:postgres:driver:桥卷:postgres:pgadmin:

igsr9ssn

igsr9ssn1#

您可以尝试评论或删除网络部分,并添加链接到链接postgres,如下所示:
链接:

  • 波斯特格雷斯
ao218c7q

ao218c7q2#

在pgAdmin中,当您添加新服务器时,您需要将“host.docker.internal”(在Windows上)定义为Host(How to add a new server)。

相关问题