Nuxt ENV not working in docker container
Hello!
I am working on a Nuxt3 project and I would like to have a docker container running it, but I'm facing some issues.
When the image is built and the container is created, the ENV variables I pass through the docker compose are not being passed to Nuxt, I can confirm this through some console logs.
What could I be doing wrong?
Dockerfile:
Docker compose:
2 Replies
Nuxt runtime config:
Use of ENV in the code:
I have solved the issue, documentation is not good at explaining this...
Envs in nuxt are read at build time and injected into the compiled solution. Thanks to the runtime config, it also has the capability of reading runtime system envs
Apparently, by default, Nuxt only reads system envs that start with "NUXT_", example: "NUXT_DBHOST". So there are 2 solutions:
- Change the env names in the docker compose, and add the NUXT prefix to all of them.
- Configure nuxt to remove/change the prefix (https://github.com/unjs/nitro/issues/1836#issuecomment-1770116095).
This can be done by adding the following to nuxt config:
GitHub
Use custom runtime environmental variables (instead of NITRO_ prefi...
Describe the feature NOTE this is reported to nuxt as well, but I open it here as well as this is related to nitro. Referring to runtime configuration (and for nuxt) , I think that the current impl...