node.jsdockernetwork-programmingprismadocker-build

Docker Build Fails Due to Network Connectivity Issue with Prisma (EAI_AGAIN)


I am experiencing a network connectivity issue while building a Docker image for my Node.js project, which uses Express and Prisma ORM to communicate with a PostgreSQL database. The error occurs specifically at the npx prisma generate step. Below is my Dockerfile:

FROM node:20

WORKDIR /app

COPY . .

RUN npm install
RUN npx prisma generate
RUN npm run build

EXPOSE 3000

CMD ["node", "dist/index.js"]

During the build process, I encounter the following error:

Error: request to https://binaries.prisma.sh/all_commits/34ace0eb2704183d2c05b60b52fba5c43c13f303/debian-openssl-3.0.x/schema-engine.sha256 failed, reason: getaddrinfo EAI_AGAIN binaries.prisma.sh

Troubleshooting Steps Taken:

  1. DNS Settings:

    • Updated Docker daemon's DNS settings to use Google's public DNS servers (8.8.8.8 and 8.8.4.4).
    • Restarted the Docker service after the changes.
  2. Network Mode:

    • Enabled Docker BuildKit and used the --network host option during the build process.
  3. Base Image:

    • Tried different Node.js base images, including node:18-alpine and node:18-slim.
  4. Proxy Check:

    • Verified that my environment variables do not indicate that I am behind a proxy.
  5. Network Connectivity Test in Temporary Container:

    • Initial success but subsequent failure in accessing the Alpine package repositories:

      docker run --rm -it alpine sh -c "apk add --no-cache curl && curl -I https://binaries.prisma.sh" 
      

      Initial output indicated connectivity:

      HTTP/2 404 
      date: Mon, 15 Jul 2024 14:57:00 GMT
      content-type: text/html
      vary: Accept-Encoding
      cache-control: max-age=120
      cf-cache-status: MISS
      server: cloudflare
      cf-ray: 8a3a9a3adc253b27-BOM
      

      Subsequent attempts failed:

      fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/main/x86_64/APKINDEX.tar.gz
      WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.20/main: temporary error (try again later)
      fetch https://dl-cdn.alpinelinux.org/alpine/v3.20/community/x86_64/APKINDEX.tar.gz
      WARNING: fetching https://dl-cdn.alpinelinux.org/alpine/v3.20/community: temporary error (try again later)
      
  6. Manual Dependency Installation:

    • Manually installed dependencies and generated Prisma client locally, then copied the generated files into the Docker image.
    • This time the build was successful and when running the container, it worked for the routes which did not use the database, but when there was a need to establish connection to the cloud database, it would fail.
  7. Busybox Container Network Test:

    • Ran a busybox container to test network connectivity:

      docker run --rm busybox ping -c 4 google.com

      Output:

      PING google.com (142.250.192.78): 56 data bytes
      64 bytes from 142.250.192.78: seq=0 ttl=254 time=44.824 ms
      64 bytes from 142.250.192.78: seq=1 ttl=254 time=44.824 ms
      64 bytes from 142.250.192.78: seq=2 ttl=254 time=44.874 ms
      64 bytes from 142.250.192.78: seq=3 ttl=254 time=45.367 ms
      
      --- google.com ping statistics ---
      4 packets transmitted, 4 packets received, 0% packet loss
      round-trip min/avg/max = 44.824/44.972/45.367 ms
      
  8. Docker Network Configuration:

    • Inspected the bridge network configuration:

      docker network inspect bridge

      Output:

      [
          {
              "Name": "bridge",
              "Id": "1b48727c2e54967fbf86f3d1c68ca36677d24f5792ffb8508dfe4e714aca9611",
              "Created": "2024-07-15T14:46:24.798485127Z",
              "Scope": "local",
              "Driver": "bridge",
              "EnableIPv6": false,
              "IPAM": {
                  "Driver": "default",
                  "Options": null,
                  "Config": [
                      {
                          "Subnet": "172.17.0.0/16",
                          "Gateway": "172.17.0.1"
                      }
                  ]
              },
              "Internal": false,
              "Attachable": false,
              "Ingress": false,
              "ConfigFrom": {
                  "Network": ""
              },
              "ConfigOnly": false,
              "Containers": {},
              "Options": {
                  "com.docker.network.bridge.default_bridge": "true",
                  "com.docker.network.bridge.enable_icc": "true",
                  "com.docker.network.bridge.enable_ip_masquerade": "true",
                  "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
                  "com.docker.network.bridge.name": "docker0",
                  "com.docker.network.driver.mtu": "1500"
              },
              "Labels": {}
          }
      ]
      

Additional Information:

Questions:

  1. How can I ensure my Docker container has proper network connectivity during the build process?
  2. Are there any additional network configurations I should consider for Docker?
  3. Could there be an issue with the Prisma binary server, and how can I work around it?

Any suggestions or solutions would be greatly appreciated. Thank you!

Request for More Information:

If you need any additional information about my environment or configuration, please let me know, and I will provide it promptly.


Solution

  • I have also tried all the measures in your question and finally found out that my router has DNS proxy enabled , i disabled and enabled the DNS proxy in my routers gateway and the issue was gone.

    If you still can't get it working . Connect your machine to your mobile data and I am sure it will work.