Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS v13.4.16 does not work in docker container #54093

Closed
1 task done
JurajKavka opened this issue Aug 16, 2023 · 16 comments · Fixed by #54102
Closed
1 task done

NextJS v13.4.16 does not work in docker container #54093

JurajKavka opened this issue Aug 16, 2023 · 16 comments · Fixed by #54102
Labels
bug Issue was opened via the bug report template. locked

Comments

@JurajKavka
Copy link

JurajKavka commented Aug 16, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

 Operating System:
      Platform: linux
      Arch: x64
      Version: #1 SMP PREEMPT_DYNAMIC Fri, 11 Aug 2023 11:03:36 +0000
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.4.16
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A
    Next.js Config:
      output: standalone

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/vercel/next.js/blob/canary/examples/with-docker/README.md

To Reproduce

Describe the Bug

Docker container with Next app starts but do not serve any content

Expected Behavior

Docker container should start and serve application

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Google Clound

@JurajKavka JurajKavka added the bug Issue was opened via the bug report template. label Aug 16, 2023
@DuCanhGH
Copy link
Contributor

DuCanhGH commented Aug 16, 2023

Can you try changing ENV HOSTNAME localhost to ENV HOSTNAME 0.0.0.0, or ENV HOSTNAME ::? Next now listens on localhost, rather than 0.0.0.0, when HOSTNAME is set to localhost :) Perhaps the Dockerfile should be updated.

@MegaOleh2
Copy link

MegaOleh2 commented Aug 16, 2023

add Labels area: examples

@MegaOleh2
Copy link

MegaOleh2 commented Aug 16, 2023

inside Dockerfile

Can you try changing ENV HOSTNAME localhost to ENV HOSTNAME 0.0.0.0, or ENV HOSTNAME ::? Next now listens on localhost, rather than 0.0.0.0, when HOSTNAME is set to localhost :) Perhaps the Dockerfile should be updated.

This is work thanks
You can check https://nodejs.org/en/docs/guides/nodejs-docker-webapp#create-the-nodejs-app
and https://bobcares.com/blog/connection-reset-by-peer-docker-error/

@michalvadak
Copy link

This is broken from 13.4.13

@kodiakhq kodiakhq bot closed this as completed in #54102 Aug 16, 2023
kodiakhq bot pushed a commit that referenced this issue Aug 16, 2023
With the latest changes in stable Next.js setting HOSTNAME is not longer required for the image to function correctly 👍 

Fixes #54093
@michalvadak
Copy link

@timneutkens Wouldn't your fix fallback to Docker's default HOSTNAME env which is the ID of the container?

@timneutkens
Copy link
Member

timneutkens commented Aug 16, 2023

@michalvadak I verified the application runs correctly when removing the HOSTNAME env var:
CleanShot 2023-08-16 at 12 19 52@2x

The reason this was set explicitly before is that there was a bug with IPv6 handling, if the hostname docker assigns was IPv6 instead of IPv4 Next.js wouldn't function correctly, that was fixed in the latest stable release thanks to @DuCanhGH, so now the HOSTNAME env var is no longer required by default 👍

@DuCanhGH
Copy link
Contributor

DuCanhGH commented Aug 16, 2023

@timneutkens you may want to update other Docker examples as well 0084166 :)

@nguaman
Copy link

nguaman commented Aug 18, 2023

Hello,
Just FYI.

If I remove 'ENV HOSTNAME 0.0.0.0', it doesn't work on Google Cloud Run.

@DuCanhGH
Copy link
Contributor

@nguaman sounds like Google Cloud Run doesn't provide HOSTNAME, perhaps a note with a commented out ENV HOSTNAME 0.0.0.0 should be added :)

@mhm13dev
Copy link

@DuCanhGH
When I try to deploy my code in a docker container with standalone mode using 13.3.4, the code is built and runs successfully.

But now I upgraded to 13.4.19 and the code is built successfully but I get this error when the container is started.

I am deploying it on AWS ECS

image

@DuCanhGH
Copy link
Contributor

@mhm13dev that doesn't even look like a proper hostname 💀 Can you try ENV HOSTNAME 0.0.0.0?

@mhm13dev
Copy link

I tried these 3 values: 0.0.0.0, localhost, ::

None of them worked.

@mhm13dev
Copy link

I think this hostname is given by AWS ECS

@DuCanhGH
Copy link
Contributor

DuCanhGH commented Aug 19, 2023

@mhm13dev if 0.0.0.0 doesn't work then I don't really know either :( I have no experience with AWS ECS as well, so I can't tell why the hostname looks like that. Doesn't look like my PR is related as it just fixes issues with IPv6, whereas this hostname most likely isn't one. You know, going from 13.3.4 to 13.4.19 is quite a jump and a lot has changed since then. Perhaps you should consider opening a separate issue.

@mhm13dev
Copy link

@DuCanhGH sure thank you.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Sep 3, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants