覆盖来自docker-compose的envvariables

我使用create-react-app创build了我的反应应用程序。 我通过.env文件中的variables定义

REACT_APP_BACKEND_BASE_URL=http://localhost:8001 

我使用“yarn build”构build了我的应用程序,并将其存储到docker映像中。

我想从我的docker-compose文件中覆盖它:

 ... environment: - REACT_APP_BACKEND_BASE_URL=http://localhost:8010 

但一旦容器开始仍然使用.env文件中的值。

我想知道是否可以从docker-compose文件覆盖它,或者如果唯一的select是在build立时设置/使用专用的.env文件。

将您的应用程序.env重命名为.env.development

如果这不起作用,那么添加.env.production来构build时间variables。

请参阅https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#what-other-env-files-can-be-used