[英]Rails: Use environment variables defined with Figaro in Docker
If I'm not wrong, it seems like defined with Figaro variables are not available in Docker container.如果我没记错的话,似乎用 Figaro 定义的变量在 Docker 容器中不可用。 I have env
files to configure Postgresq DB: POSTGRES_USER=ENV['db_user'] POSTGRES_PASSWORD=ENV['db_password] POSTGRES_DB=ENV['db_name']
I have application.yml
file copied with all the other Rails app files to the container (I could check it with ls
in the container shell).我有env
文件来配置 Postgresq DB: POSTGRES_USER=ENV['db_user'] POSTGRES_PASSWORD=ENV['db_password] POSTGRES_DB=ENV['db_name']
我将application.yml
文件与所有其他 Rails 应用application.yml
文件一起复制到容器中(我可以在容器外壳中使用ls
进行检查)。
Is it a normal behaviour ?这是正常行为吗?
I also faced this issue when working on a Rails application.在处理 Rails 应用程序时,我也遇到了这个问题。
The thing to note here is that for Docker , environment variables are placed in a .env
file or an env_file
( my_variables.env
).这里要注意的是,对于Docker ,环境变量放置在.env
文件或env_file
( my_variables.env
) 中。 Environment files placed in .yml
or .yaml
files ( application.yml
) are not often recognized by Docker during runtime.放置在.yml
或.yaml
文件( application.yml
)中的环境文件在运行时通常不会被 Docker 识别。 Here's a link to Docker's official documentation that further explains it: The “.env” file这是 Docker 官方文档的链接,进一步解释了它: “.env”文件
An example of such environment variables are Database connection strings which are required during the application startup process like:此类环境变量的一个示例是在应用程序启动过程中所需的数据库连接字符串,例如:
database_name
database_username
database_password
However, you can still use the Figaro gem for defining variables that are not required during application startup, like:但是,您仍然可以使用 Figaro gem 来定义应用程序启动期间不需要的变量,例如:
RAILS_MASTER_KEY
That's all.就这样。
I hope this helps我希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.