dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
20.95k stars 4.9k forks source link

This example does not work when you publish/run in WSL 2 #5320

Closed samgithub closed 8 months ago

samgithub commented 4 years ago

My target platform is a linux-64, so I am pre-publishing the microservice using Step 1: dotnet publish -c Release -o publish -r linux-x64

Then I create an image using docker build -t microservice -f Dockerfile .

Then create a container within WSL Ubunto 20.0.4

docker run -it --rm -p 3000:80 --name microservicecontainer microserviceI

Problem : I cannot access the service from a browser on Win10) (http://localhost:3000)


Results From docker run in WSL info: Microsoft.Hosting.Lifetime[0] Now listening on: http://localhost:5000 info: Microsoft.Hosting.Lifetime[0] Now listening on: https://localhost:5001 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: /publish info: Microsoft.Hosting.Lifetime[0]


I noticed that Ketrel was listening to 5000 and 5001

So I changed the run to: docker run -it --rm -p 5000:80 --name microservicecontainer microserviceI BUT http://localhost:5000 doesn't work either.

My Dockerfile


FROM mcr.microsoft.com/dotnet/core/sdk:3.1 COPY ./publish /publish WORKDIR /publish ENTRYPOINT ["dotnet", "myMicroservice.dll"]


The example as shown does work - but its strictly a Windows sample. REQUEST: Can you provide the same sample, publish to a Linux-64 target; and run it under WSL? --- please.

mairaw commented 4 years ago

Where are you seeing this example @samgithub?

samgithub commented 4 years ago

Its the example at

https://dotnet.microsoft.com/learn/aspnet/microservice-tutorial/intro

mairaw commented 4 years ago

Adding @shirhatti and @nishanil to help here

We do offer Linux versions of the tutorials too - just click on the Linux tab: https://dotnet.microsoft.com/learn/aspnet/microservice-tutorial/intro?initial-os=linux

And then we also have a deployment one: https://dotnet.microsoft.com/learn/aspnet/deploy-microservice-tutorial/intro?initial-os=linux

Does that help?

samgithub commented 4 years ago

Thanks for your response and attention to this matter.. Actually I already looked at the Linux tabs and they essentially involve using Linux as the development environment. Just to avoid confusion my process is as follows:

1) Development environment Win 10 - Visual Studio 2) Publishing TARGET : Linux (using dotnet publish -c Release -o publish -r linux-x64) 3) Create a docker image from the linux bits in the publish folder. 4) Create a container from step (3) in WSL (Ubuntu)

The above steps are fine BUT navigating to localhost:3000/weatherforecast ---> DOES NOT WORK.

samgithub commented 4 years ago

Since VS is cross-platform and allows publishing to different targets, an example would greatly help. Thanks

mairaw commented 4 years ago

@shirhatti @nishanil can you help on this issue?

nishanil commented 4 years ago

hey @samgithub ! I followed the exact steps listed on that the page and was able to run it inside WSL. See this video: https://1drv.ms/u/s!AupZwrZ-sEsggZw9dmMeGjgZe7oG-Q?e=Dfn1ru

nishanil commented 4 years ago

I added some log info for you. image Try executing the exact steps listed in the page https://dotnet.microsoft.com/learn/aspnet/microservice-tutorial/intro?initial-os=linux first. Then compare the code with yours to see what you were doing wrong,

samgithub commented 4 years ago

Are you creating a LINUX IMAGE? That's what I'm talking about. The Windows image works. Its the publish to linux-x64 and Use a container from it that does not work.

On Wed, Oct 14, 2020, 2:23 PM Nish Anil notifications@github.com wrote:

I added some log info for you. [image: image] https://user-images.githubusercontent.com/3107766/96029227-fb015e00-0e77-11eb-9a48-f0c85d6e3a43.png Try executing the exact steps listed in the page https://dotnet.microsoft.com/learn/aspnet/microservice-tutorial/intro?initial-os=linux first. Then compare the code with yours to see what you were doing wrong,

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dotnet/core/issues/5320#issuecomment-708579126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFSTR325ZVBZ3XT45NCFQ3SKXUAPANCNFSM4SJIJNZQ .

nishanil commented 4 years ago

Yes, it is a Linux image. See the OS Version.

mairaw commented 8 months ago

Given this is a bit old and beyond the scope of the tutorial, I'm closing this. Please reactivate if you still need assistance.