I’m running a aspnet core application with an SPA created using creat-react-app.
In this application I use some environment variables in the client. The official way to do this with this tool is to prefix the variables with “REACT_APP_”. (https://create-react-app.dev/docs/adding-custom-environment-variables/)
I’ve created these variables in my component settings. By default these are scoped as RUN_AND_BUILD_TIME. But they don’t seem to be available when my page is being built.
I added a couple of extra RUN instructions in my docker file to try and print these variables, they come out empty.
My application’s dockerfile is based on example provided here:
https://docs.docker.com/samples/dotnetcore/
With the only modification being the installation of nodejs.
Thanks in advance, any help or clarification will be greatly appreciated. Hopefully I just missed something from the docs :)
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hey there!
You mentioned you are running this from a Dockerfile.
Environment variables are only available as build-args for Dockerfile builds in App Platform. So you should declare them in the Dockerfile as an ARG and then set the ENV variable in the Dockerfile from the build-arg.
Something like this may work:
ARG TEST_VARIABLE
ENV TEST_VARIABLE=${TEST_VARIABLE}
hello I got the same error like that, but when I exec the docker in local I have my env var but with app platform I didn’t have it
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.