Next.js Discord

Discord Forum

Next 13 standalone server doesn't work in docker container

Answered
Golden northern bumble bee posted this in #help-forum
Open in Discord
Golden northern bumble beeOP
So I build my project with output: standalone option with npm run build
Then I copy .next/standalone into a docker image created from node:16-alpine
However, when I start server.js and open it from the browser, it returns 500 Internal Server Error and prints this in the console:
Listening on port 3000 url: http://480ba79a78f0:3000
- error Failed to handle request for /
TypeError: fetch failed
    at Object.fetch (/app/node_modules/next/dist/compiled/undici/index.js:1:26669)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async invokeRequest (/app/node_modules/next/dist/server/lib/server-ipc/invoke-request.js:21:12)
    at async requestHandler (/app/node_modules/next/dist/server/lib/start-server.js:336:33)
    at async Server.<anonymous> (/app/node_modules/next/dist/server/lib/start-server.js:152:13) {
  cause: Error: connect ECONNREFUSED 127.0.0.1:33593
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1278:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 33593
  }
}

What is going on? I don't have an idea what it is trying to do: why is it connecting to localhost:33593 for example? Why it can't fetch even the first page? It worked before on Next 12 projects.
Answered by European sprat
if you downgrade to nextjs 13.4.12 it should work
View full answer

9 Replies

European sprat
there's a few bugs right now, let me find the issues
European sprat
if you downgrade to nextjs 13.4.12 it should work
Answer
European sprat
Actually the one i was thinking of is resolved in latest nextjs but they also introduced another bug where env vars don't get passed into the container.

in any case, try 13.4.12 and see if it works
Golden northern bumble beeOP
Thanks @European sprat ! I'll check which version I use
"13.4.13" is mine
Looks up to date
oh, you mean DOWNgrade
ok, sorry
Golden northern bumble beeOP
@European sprat Oh, thank you very much. Downgrading to 13.4.12 has helped! Magic!