dotenv-run
dotenv-run copied to clipboard
Issue when running Angular app in a Docker container
Hello, I am using
"dependencies": {
"@angular-devkit/build-angular": "20.3.1",
"@angular/core": "20.3.0",
"@ngx-env/builder": "^20.1.1",
}
I have followed the steps in the README so I have created an environment.ts file
export const environment = {
production: true,
deploymentColor: import.meta.env.NG_APP_DEPLOYMENT_COLOR,
deploymentVersion: import.meta.env.NG_APP_DEPLOYMENT_VERSION
};
and the env.d.ts created when I add the @ngx-env
// Define the type of the environment variables.
declare interface Env {
readonly NODE_ENV: string;
// Replace the following with your own environment variables.
// Example: NGX_VERSION: string;
readonly NG_APP_DEPLOYMENT_COLOR: string;
readonly NG_APP_DEPLOYMENT_VERSION: string;
}
// Choose how to access the environment variables.
// Remove the unused options.
// 1. Use import.meta.env.YOUR_ENV_VAR in your code. (conventional)
declare interface ImportMeta {
readonly env: Env;
}
When I deploy via ng serve or a production build locally everything is fine and opening the Chrome dev tools I can see the file <define:_NGX_ENV_> is correctly populated with the env var I have defined via export.
When I pack my app into a Docker container the <define:_NGX_ENV_> file is empty, is there any advice to build the docker image?
I have seen the example but I don't want to pass the env var as argument during the build, when I start the container I simply pass -e NG_APP_DEPLOYMENT_COLOR='green' etc.