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

[Bug] 我采用本地build 成镜像后,是否该镜像不会采用.env.local 的配置,我发布上去一直显示需要配置KEY #6341

Open
Austin-Patrician opened this issue Mar 6, 2025 · 7 comments
Labels
bug Something isn't working

Comments

@Austin-Patrician
Copy link

📦 部署方式

Docker

📌 软件版本

💻 系统环境

Ubuntu

📌 系统版本

19.2

🌐 浏览器

Chrome

📌 浏览器版本

latest

🐛 问题描述

我需要将请求openai 的接口放到自己定义的后台项目,并且在.env.local配置了自己的jwt token,自己的baseurl, 在本地开发debug完全没问题,但是当我本地docker build 后(已经将.env.local 从docker ignore 移除)后,发布到外网,会显示未配置APIKEY的问题。请问我还需要在docker file 直接配置key 么?但是我没看到baseurl 选择,该如何配置?(我的后台接口可以Postman 调通)

📷 复现步骤

No response

🚦 期望结果

docker 本地部署后应该启动正常,可以调通接口。

📝 补充信息

No response

@Austin-Patrician Austin-Patrician added the bug Something isn't working label Mar 6, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: [Bug] After I use local build to mirror, will the image not be configured with .env.local? I have been posting it and always show that I need to configure KEY

📦 Deployment method

Docker

📌 Software version

none

💻 System environment

Ubuntu

📌 System version

19.2

🌐 Browser

Chrome

📌 Browser version

Latest

🐛 Question description

I need to put the interface requesting openai into the background project I defined, and configure my own jwt token and my own baseurl in .env.local. It is completely fine to develop debug locally. However, after I build the local docker (which has removed .env.local from docker ignore), and publish it to the external network, the problem of APIKEY not configured is displayed. Do I still need to configure the key directly in the docker file? But I didn't see the baseurl selection, how to configure it? (My backend interface can be adjusted by Postman)

📷 Reproduction steps

No response

🚦 Expected results

Docker should start normally after local deployment, and the interface can be adjusted.

📝 Supplementary information

No response

@Kosette
Copy link
Contributor

Kosette commented Mar 6, 2025

不要将任何secrets直接打包进docker镜像,镜像中的文件都是可以被看到的,密钥之类的在运行时传入。

如果你用的是项目自带的打包流程,那么所有的配置项基本都是由环境变量传入的。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Do not package any secrets directly into the docker image. The files in the image can be seen, and keys and other files are passed in at runtime.

If you are using the package process that comes with the project, then all configuration items are basically passed in by environment variables.

@Austin-Patrician
Copy link
Author

不要将任何secrets直接打包进docker镜像,镜像中的文件都是可以被看到的,密钥之类的在运行时传入。

如果你用的是项目自带的打包流程,那么所有的配置项基本都是由环境变量传入的。

首先是本地自建的.env.local 在本地开发的时候是生效的,server.ts 是可以读到值的,但是当我本地docker build -t . 的时候,发现其server.ts 并没有办法读取到.env 里面的值,并且我已经把.env 从docker ignore 里面移除掉,我们基于自己的azure acr 来存储镜像。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Do not package any secrets directly into the docker image. The files in the image can be seen, and keys and other types are passed in at runtime.

If you use the package process that comes with the project, then all configuration items are basically passed in by environment variables.

First of all, the local self-built .env.local was effective during local development, and server.ts can read the value, but when I built the local docker -t ., I found that its server.ts cannot read the value in .env, and I have removed .env from docker ignore. We store the image based on our own azure acr.

@Kosette
Copy link
Contributor

Kosette commented Mar 7, 2025

@Austin-Patrician

首先是本地自建的.env.local 在本地开发的时候是生效的,server.ts 是可以读到值的,但是当我本地docker build -t . 的时候,发现其server.ts 并没有办法读取到.env 里面的值,并且我已经把.env 从docker ignore 里面移除掉,我们基于自己的azure acr 来存储镜像。

生产环境默认不会读取.env.local或者.env文件中的配置,请使用环境变量之类的方法进行配置,我知道你在开发环境是生效的。Docker的环境变量配置方法可以看一下文档,docker compose也可以通过.env文件传入,不需要打包进image。

项目的.env和docker compose的.env是不同的东西。遇到不懂的可以先问问AI,这些部分AI回答得比人全面。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


@Austin-Patrician

First of all, the local self-built .env.local was effective during local development. Server.ts can read the value, but when I built the local docker -t ., I found that its server.ts cannot read the value in .env, and I have removed .env from docker ignore. We store the image based on our own azure acr.

The production environment will not read the configuration in the .env.local or .env file by default. Please use methods such as environment variables to configure it. I know that your development environment is effective. You can check the documentation for Docker's environment variable configuration method. Docker compose can also be passed in through .env files, and there is no need to package it into image.

The project's .env and docker compose .env are different things. If you encounter someone who doesn’t understand, you can ask about AI first. These AI answers are more comprehensive than others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants