NextJS with Docker not working properly in Production
Unanswered
Tosa posted this in #help-forum
TosaOP
Hey! I am trying to host my NextJS site on Docker. Everything works perfectly fine locally. But when hosted on Docker, hooks such as useEffect doesn't appear to be working, some images don't load (they are all from the same CDN).
- This is hosted on a server with plenty of resources
- Its just a normal npm run build and npm run start
- I am using node:21-alpine for the docker image (used node 21.2.0 for dev)
Any idea what tf is causing all this?
- This is hosted on a server with plenty of resources
- Its just a normal npm run build and npm run start
- I am using node:21-alpine for the docker image (used node 21.2.0 for dev)
Any idea what tf is causing all this?
19 Replies
TosaOP
Ill probably try using a non alpine version of node tomorrow and see if thats the problem. But I am using
libc6-compat as well which was recommended in the docker example (they also used an alpine version)TosaOP
If you look at the topbar, the user icon and the theme toggle button aren’t there.
The theme toggle is invisible until the useEffect hook fired and updates a state to prevent a hydration error
But it never becomes visible on there.
@Tosa sure https://teststore.myhostcore.com/dashboard
Dunker
i am seeing UserIcon instead img
can i see that code makes this
also are you seeing any logs at your hosting dashboard or somewhere
Dunker
i am seeing 404 at here
https://cdn.hostcore.co/assets/default/usericon.jpg&w=64&q=75/_next/image?url=https%3A%2F%2Fcdn.hostcore.co%2Fassets%2Fdefault%2Fusericon.jpg&w=64&q=75TosaOP
Yeah that’s NextJS, if you were to look at: https://cdn.hostcore.co/assets/default/usericon.jpg it works fine
@Tosa Yeah that’s NextJS, if you were to look at: https://cdn.hostcore.co/assets/default/usericon.jpg it works fine
have you set the
remotePatterns in next.config.js?some docker image has issue with sharp
TosaOP
Ok I’ll have a look at that. I am using sharp.
TosaOP
Figured out the problem with the image, nextjs requires the nextjs.conf file to be in the docker image as well (I assumed all required stuff would be in the .next folder)
And adding a line to the image that npm rebuilds sharp fixed that as well
Just need to sort out the theme switching icon not ever showing up.