vercel / next.js

The React Framework
https://nextjs.org
MIT License
123.52k stars 26.35k forks source link

Docker image ignores signals #65088

Open cristi8 opened 3 months ago

cristi8 commented 3 months ago

Verify canary release

Provide environment information

n/a

Which example does this report relate to?

with-docker

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

The docker container ignores all signals.

I also found the problem. Things got broken by #59756 where the main process in the docker container was replaced with a bash shell, handling the env variable. If i use the original

ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]

things work as expected.

My guess is the fix is not that easy, as it might reopen #58657

IMHO, the HOSTNAME env variable name choice was not that good for specifying the network interface where it binds. And it might be a good time to change it to something more suitable now, since from what i understood, it was recently introduced and not documented anyway

Expected Behavior

Current behavior: it ignores Ctrl+C Expected: It finishes the current connections and gracefully closes

To Reproduce

Use the example Dockerfile, create a container, run it with -it, then press Ctrl+C

cristi8 commented 2 months ago

Found a workaround that still works for k8s / ECS:

# HOSTNAME variable is set like this to ensure it's not overwritten by k8s / ECS when running the container
CMD ["/bin/sh", "-c", "exec env HOSTNAME=0.0.0.0 node server.js"]

by using exec, the node process becomes PID 1 and handles signals correctly

r34son commented 1 month ago

Related https://docs.docker.com/reference/build-checks/json-args-recommended/