skip to Main Content

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 Ctrlu002BC to shut down.","State":{"Message":"Application started. Press Ctrlu002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrlu002BC 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?

2

Answers


  1. 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
    
    Login or Signup to reply.
  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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search