Postgres和PgAdmin Docker组成静态IP连接错误

时间:2019-09-17 11:46:27

标签: docker docker-compose

我正在尝试使用docker compose来启动postgres和pgadmin。但是,我想使用静态ip运行postgres,以免每次都无法通过pgAdmin建立服务器连接。当我不使用静态ip时,它可以成功连接到服务器,但是在添加静态ip之后,服务器连接将失败。

docker-compose.yml-具有静态IP配置;

version: '3.2'

services:
  postgresql:
    container_name: postgres-latest
    image: postgres
    networks:
      default:
      outside:
        ipv4_address: 192.168.220.220
    expose:
      - "5432"
    ports:
      - 5432:5432
    volumes:
      - ./volumes/postgres-data:/var/lib/postgresql/data
    environment:
      - 'POSTGRES_USER=postgres'
      - 'POSTGRES_PASSWORD=docker'
      - 'POSTGRES_DB=jira_db'
      - 'POSTGRES_ENCODING=UTF-8'

  pgadmin:
    container_name: pgadmin4-latest
    image: dpage/pgadmin4
    restart: always
    depends_on:
      - postgresql
    ports:
      - 5454:5454/tcp
    environment:
      - PGADMIN_DEFAULT_EMAIL=ali.turkkan@hotmail.com.tr
      - PGADMIN_DEFAULT_PASSWORD=docker
      - PGADMIN_LISTEN_PORT=5454
    volumes:
      - ./volumes/pgadmin-data:/var/lib/pgadmin
    networks:
      - default

volumes:
  postgres-data:
    external: false
  pgadmin-data:
    external: false

networks:
  outside:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 192.168.220.0/24

docker-compose-没有静态ip配置;

version: '3.2'

services:
  postgresql:
    container_name: postgres-latest
    image: postgres
    networks:
      - jiranet
    expose:
      - "5432"
    ports:
      - 5432:5432
    volumes:
      - ./volumes/postgres-data:/var/lib/postgresql/data
    environment:
      - 'POSTGRES_USER=postgres'
      - 'POSTGRES_PASSWORD=docker'
      - 'POSTGRES_DB=jira_db'
      - 'POSTGRES_ENCODING=UTF-8'

  pgadmin:
    container_name: pgadmin4-latest
    image: dpage/pgadmin4
    restart: always
    depends_on:
      - postgresql
    ports:
      - 5454:5454/tcp
    environment:
      - PGADMIN_DEFAULT_EMAIL=ali.turkkan@hotmail.com.tr
      - PGADMIN_DEFAULT_PASSWORD=docker
      - PGADMIN_LISTEN_PORT=5454
    volumes:
      - ./volumes/pgadmin-data:/var/lib/pgadmin
    networks:
      - jiranet

volumes:
  postgres-data:
    external: false
  pgadmin-data:
    external: false

networks:
  jiranet:
    driver: bridge

虽然我无法使用在第一个配置中设置的静态IP连接到pgadmin,但可以使用在第二个设置中自动确定的IP地址连接到服务器。可能是什么原因?

0 个答案:

没有答案