将Docker容器连接到数据库服务器

时间:2020-06-02 19:13:51

标签: mysql docker-compose containers dock

将docker容器连接到MySQL数据库远程服务器时,出现以下错误。

Could not connect to database! SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

下面是我的docker-compose.yml

version: '3'

services:
  phpipam-web:
    image: pierrecdn/phpipam:latest
    ports:
      - "8080:80"
    networks:
      hostnet: {}
    environment:
      - TZ=UTC
      - IPAM_DATABASE_HOST=192.168.56.120
      - IPAM_DATABASE_USER=root
      - IPAM_DATABASE_PASS=abas1234
      - IPAM_DATABASE_NAME=phpipam
    restart: unless-stopped
    volumes:
      - phpipam-www:/var/www/html

volumes:
  phpipam-www:
networks:
  hostnet:
   external: true

NETWORK ID          NAME                DRIVER              SCOPE
03ffbac296b0        bridge              bridge              local
98e738b65aec        host                host                local
5c2034e74b2b        hostnet             bridge              local
d6e894428248        none                null                local
5f95003cb178        phpipam_default     bridge              local

注意:我没有将Mysql数据库作为容器运行,而是在远程服务器上。

有人知道如何将Docker容器与远程主机进行通信吗?

0 个答案:

没有答案