2

I've got an ASP.NET core 2.2 web app that I have enabled docker support for. I have created a test app here for review here.

I am running it in VS with Docker locally. I want to add environment variables/secrets to the app settings secrets in order to override the values in the appsettings.json file. In order to do this locally, I have tried changing values in:

however, for both of these, when I attach to my docker instance and printenv the variable values, I find that the variable for ASPNETCORE_ENVIRONMENT still shows up as Development.

I am attaching to the running container like this:

docker exec -t -i 4c05 /bin/bash

I have searched all files in my solution. I can't find ASPNETCORE_ENVIRONMENT being set to Development anywhere in the solution. However, somehow, the environment variable is still being set with that value.

What could be going wrong? I want that variable to change. Once working, what I really want to do is to add a connection string secret to environment variables so that it can be used locally via the appsettings.json file or via a docker secret environment variable if the aspnetcore web app is running in a container. I think I've got this code working, it's just that the variables are not being deployed as expected to the running container.

My VS version is: VS version

thanks

6
  • can you show me how you're looking for the environment variable ? I see you're running bash, but that doesn't show me what you did to theoretically check for the evnrionment variable. Your dockerfile definitely sets it (misspelling / typos notwithstanding) Commented Dec 27, 2018 at 22:38
  • hi Dan, I am running this: docker exec -t -i 4c83 /bin/bash. Once connected, I then run printenv. of course 4c83 is the container id Commented Dec 27, 2018 at 22:53
  • I'm just trying it using docker-compose now. I have added Orchestrator Support to the web project Commented Dec 27, 2018 at 22:54
  • your use of env seems correct to me, fwiw. Commented Dec 27, 2018 at 23:05
  • I downloaded and ran your code (on a mac) and got the correct env variable printed from printenv: dropbox.com/s/1fsjx5650nt5sfo/… - must be something VS is doing? Commented Dec 27, 2018 at 23:12

1 Answer 1

1

Mmm - seems there is a problem with DockerFile support in VS. However, when I use the Orchestration Support, using docker-compose, the functionality works as expected, so I'm answering the question myself :-)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.