Next.js Discord

Discord Forum

Cannot load env vars with SSR in Docker Container

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
i have the following server component:

import { ClientDashboardPage } from "./client_page";

const DashboardPage = async () => {
// Google
const googleClientId = process.env.GOOGLE_CLIENT_ID!;
const googleRedirectURI = process.env.REDIRECT_URI!;

// Microsoft
const microsoftClientId = process.env.APPLICATION_ID!;
const microsoftRedirectURI = process.env.MICROSOFT_REDIRECT_URI!;
// const microsoftTenantId = process.env.TENANT_ID!;

return (
<ClientDashboardPage
googleClientId={googleClientId}
googleRedirectURI={googleRedirectURI}
microsoftClientId={microsoftClientId}
microsoftRedirectURI={microsoftRedirectURI}
/>
);
};

export default DashboardPage;

in dev mode the env Variables are loaded correctly. the same code does not load the env Variables anymore when inside of a Docker container though. here is my compose.yml:

services:

webapp:
build:
context: ./webapp
dockerfile: Dockerfile
ports:
- "3001:3001"
env_file: "webapp/.env"
restart: always

when inspecting the running containers env Vars though, they are all there. So Docker seems to load them but a SC cannot read them. does anybody have a clue why or an alternative way of loading the env?

0 Replies