node.jsdockerfly

Fly.io Launch Issue: "Error failed to fetch an image or build from source: error building: error during connect: Post..."


I am new to Docker and Fly.io, and trying to get a very basic Nodejs backend hosted, but running into an error. You can see my repo here. Locally, I've added a Dockerfile to backend/ that looks like this:

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
EXPOSE 5000
CMD ["node", "app.js"]

Then, in WSL2, I ran docker build . and docker run -dp 5000:5000 [image ID]. The backend is showing at localhost:5000 as well as feeding data to the frontend correctly.

But when I run flyctl launch, it keeps giving me Error failed to fetch an image or build from source: error building: error during connect: Post "http://[a very long URL]": EOF.

Someone suggested that the auto-generated fly.toml defaulting to internal_port = 8080 was the issue, so I tried changing it to match Express and Docker with 5000, but got the same error.

Just in case: I have a bad Internet connection and I don't know if that could be the problem--a timeout?

Can someone help me??


Solution

  • I was able to fix this and I'm posting it here for others who I saw had the same issue.

    My guess is that the problem was that just altering the 5000 to 8080 in the fly.toml file that had been made during a failed build was not enough. It needed to be correct from the start.