0

I have

  1. Forked the planetaryDocs project (a sample server resident Blazor Web App),
  2. Used Visual Studio 2022 to create a docker container
  3. Run that docker container (via Visual Studio) and

and Visual Studio pops up a browser pointing at the web server and it seems to working fine.

When I do docker image ls I see the planetarydocs image.

I want to experiment with the docker run command line. How do I do that? I stop the Visual Studio docker container and

docker.exe run planetarydocs  -p 9090:80

This does not work.

I point my browser at http://localhost:9090 and the browser says "cannot reach this page".

What am I doing wrong?

Thanks!

Here is that is displayed with the above docker command:

   {"EventId":35,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager","Message":"No XML encryptor configured. Key {3df3c08f-884d-49fe-a4f8-163ea6058090} may be persisted to storage in unencrypted form.","State":{"Message":"No XML encryptor configured. Key {3df3c08f-884d-49fe-a4f8-163ea6058090} may be persisted to storage in unencrypted form.","KeyId":"3df3c08f-884d-49fe-a4f8-163ea6058090","{OriginalFormat}":"No XML encryptor configured. Key {KeyId:B} may be persisted to storage in unencrypted form."}}
   {"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:80","State":{"Message":"Now listening on: http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now listening on: {address}"}}
   {"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application started. Press Ctrl\u002BC to shut down.","State":{"Message":"Application started. Press Ctrl\u002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC to shut down."}}
   {"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting environment: Production","State":{"Message":"Hosting environment: Production","envName":"Production","{OriginalFormat}":"Hosting environment: {envName}"}}
   {"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content root path: /app","State":{"Message":"Content root path: /app","contentRoot":"/app","{OriginalFormat}":"Content root path: {contentRoot}"}}

2021 Dec 31 Fri Update

OK, I'm embarrassed: this works!

docker.exe run -p 9090:80 planetarydocs

It would be nice if docker run gave me a hint that I was ordering my switches wrong...

Can someone point me to the documentation that describes this funny syntax for docker in the launchsettings.json?

"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "publishAllPorts": true,
  "useSSL": true
}
  1. I kept looking at appsettings.json and launchsettings.json thinking the ports for docker should be in there and they are not. Where are ServicePort and ServiceHost and scheme defined?

  2. Does this have something to do with the fact that Visual Studio uses a new port every time it launches the application from a docker container? Why does it do that?

  3. Since port 80 works, should not port 80 be defined somewhere in these config files?

  4. Who uses this launchsettings config file? Visual Studio only? I guess we ignore config file(s) if we are running docker from the command line?

1
  • I thought at first you have used wrong port numbers, but @hans-kilian's below is the most possible cause to your problem: the order of parameters in the command. Commented Dec 31, 2021 at 12:30

2 Answers 2

2

Your run command is wrong. Any parameters to Docker need to go before the image name. Any parameters after the image name override any CMD definition in the image.

So instead of

docker.exe run planetarydocs  -p 9090:80

you should do

docker.exe run -p 9090:80 planetarydocs
Sign up to request clarification or add additional context in comments.

Comments

0

from the repository you pointed, the app seems to use port 8081.

PlanetaryDocs/appsettings.json

"EndPoint": "https://localhost:8081/",

if you haven't changed it,try this command using that port instead

docker.exe run planetarydocs  -p 9090:8081

4 Comments

The aspnet image from Microsoft (which OP's project is most likely using) sets ASPNETCORE_URLS to http://+:80 and overrides any endpoint definitions in the project.
ah ok, seeing your posted answer I realized the OP might have missed the error docker gave about port mapping thus refusing to start ever. I missed that.
Yilmaz: 8081 is the port for Jeremy's Cosmos DB emulator, not the web app.
Hans: good to know. This is confusing because Visual Studio overrides ASPNETCORE_URLS with a port of 5000 in the launchsettings.json.

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.