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??

1

There are 1 best solutions below

0
On BEST ANSWER

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

  • I have read that you need a host of '0.0.0.0' in the app.listen, so that was there (didn't solve my issue but maybe someone else's)
  • destroyed the fly attempted build
  • deleted the fly.toml
  • deleted the Docker container and image
  • changed my backend port to 8080 across my project (the auto-generated fly.toml makes internal_port = 8080 no matter what the Dockerfile says)
  • remade the Docker container and image
  • ran flyctl launch again

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.