0

.Net core 5.0.103

docker version: 20.10.2, build 2291f61 (Ubuntu)

I create docker image + try to get environment variables from command line. So:

docker run -it --rm robust_tapir -e ADDRESS='127.0.0.1' -e Port='5000' -e Schema='http'

And result is:

[15:08:57 ERR] Hello World!
[15:08:57 ERR] Address:
[15:08:57 ERR] Port:
[15:08:57 ERR] Schema:

In my .net core console app:

            Logger = CreateLogger();
            Logger.Error("Hello World!");

            await Task.Delay(5);

            Address = Environment.GetEnvironmentVariable("ADDRESS");
            Port = Environment.GetEnvironmentVariable("Port");
            Schema = Environment.GetEnvironmentVariable("Schema");
       
#if DEBUG
            Address = "127.0.0.1";
            Port = "5000";
            Schema = "http";
#endif
            Logger.Error($"{nameof(Address)}:{Address}");
            Logger.Error($"{nameof(Port)}:{Port}");
            Logger.Error($"{nameof(Schema)}:{Schema}");

            while (string.IsNullOrEmpty(Address))
            {
                await Task.Delay(1000);
            }
                                           

So, what i do wrong? Wrong pass into container or wrong read it from .net core?

2
  • 3
    Try removing single quotes surrounding 127.0.0.1, 5000 and http. Commented Feb 21, 2021 at 15:20
  • 1
    I had the same issues and I moved the image name to the end of the line and it fixed it Commented Jun 21, 2022 at 0:47

1 Answer 1

1

Quotes goes around the entire env. argument:

docker run -it --rm robust_tapir -e "ADDRESS=127.0.0.1" -e "Port=5000" -e "Schema=http"
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.