1 回答

TA贡献1804条经验 获得超7个赞
如果你已经在使用 你的,你真的不需要godotenv,因为环境已经从docker-compose传下来了:env_filedocker_compose.yml
version: '3'
services:
app:
image: busybox:latest
command: sh -c 'echo "Hello $$USER!"'
env_file:
- .env
# .env
USER=user1
$ docker-compose up
Recreating test_app_1 ... done
Attaching to test_app_1
app_1 | Hello user1!
test_app_1 exited with code 0
这比尝试将 .env 文件复制到容器中更好,因为这意味着您可以传递环境变量,而无需在每次;)
如果你仍然想使用godotenv,我发现通过简单地从Dockerfile中取消注释该行,.env文件可以正确加载(因为godotenv在目录中找到了它,而如果它被注释,它就不会)。COPY --from=builder /app/.env .
$ docker-compose up
Starting template_123 ... done
Attaching to template_123
template_123 | We are getting the env values
template_123 | thisismyenvvariable
template_123 exited with code 0
如果你想让它与你的文件系统保持同步,你需要使用一个卷来链接你的.env和文件系统上的那个,或者正如我所说,完全放弃,因为它在你的情况下并不是很有用。godotenv
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报