host.docker.internal 无法在 prismagraphql/prisma:1.34 上运行 docker-compose (1.29.2) docker 20.10.9 CentOS 8.4.2105

host.docker.internal not working on prismagraphql/prisma:1.34 on docker-compose (1.29.2) docker 20.10.9 CentOS 8.4.2105

我想部署一个 'prismagraphql/prisma:1.34' 容器使用:

但是当我在主机上使用 'host.docker.internal' 时无法正常工作。 所以我尝试使用:

extra_hosts:
        - "host.docker.internal:host-gateway"

我的项目三个文件:

datamodel.prisma :

type User {
  id: ID! @id
  name: String!
}

prisma.yml :

endpoint: http://localhost:4477
datamodel: datamodel.prisma

docker-compose.yml :

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.34
    restart: always
    extra_hosts:
    - "host.docker.internal:host-gateway"
    ports:
    - "4477:4477"
    environment:
      PRISMA_CONFIG: |
        port: 4477
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: host.docker.internal
            database: postgres
            schema: public
            user: postgres
            password: yrt
            rawAccess: true
            port: '5432'
            migrations: true

我尝试了很多事件来禁用防火墙添加到 /etc/hosts ... => 不工作

我在这里创建一个 GitHub 存储库:https://github.com/performautodev/local-prisma-1.34-using-docker-compose-1.29.2-docker-20.10.9-on-CentOS-8.4.2105

host.docker.internal 在 Linux 上不受支持。查看 this Whosebug 的解决方法答案。

✔️ 已解决:

答案是使用这个命令的输出:

ip route | grep docker0 | awk '{print }'

[root@localhost dev]# ifconfig docker0
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:e6ff:fe93:a426  prefixlen 64  scopeid 0x20<link>
        ether 02:42:e6:93:a4:26  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1  bytes 90 (90.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

并使用行:

inet 172.17.0.1

所以 yml 文件看起来像这样:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.34
    restart: always
    ports:
    - "4477:4477"
    environment:
      PRISMA_CONFIG: |
        port: 4477
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: 172.17.0.1
            database: postgres
            schema: public
            user: postgres
            password: 'YOUR_PASS'
            rawAccess: true
            port: '5432'
            migrations: true

重要: 我的 /etc/hosts 是默认值:

[root@localhost dev]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

问题参考:

https://github.com/docker/compose/issues/8771

https://github.com/moby/moby/issues/42919

https://github.com/prisma/prisma/issues/9677