Cannot run asp.net 5 from docker

前端 未结 4 412
清酒与你
清酒与你 2020-12-17 01:47

I have followed the following guide: Running ASP.NET 5 applications in Linux Containers with Docker and I cannot get this to work on my Windows PC or Linux server. My docker

相关标签:
4条回答
  • 2020-12-17 02:01

    For anyone having this issue now in RC2, commands no longer exists. You have to update Program.cs by chaining in .UseUrls("http://0.0.0.0:5000"). You can also change from 5000 to whatever your desired port is here.

    public class Program
    {
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseUrls("http://0.0.0.0:5000")
                .Build();
    
            host.Run();
        }
    }
    
    0 讨论(0)
  • 2020-12-17 02:04

    You can find a working, step-by-step tutorial for Docker and ASP.NET Core RC1 here: https://www.sesispla.net/blog/language/en/2015/12/recipe-asp-net-5-net-core-to-the-docker-container/

    The tricky part probably you are missing is to modify your projects.json command as follows:

      "commands": {
        "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000"
      },
    

    By default, kestrel only accepts localhost connections... With this change you allow connection from any source.

    0 讨论(0)
  • 2020-12-17 02:14

    Take a look at my answer here: ASP.NET 5.0 beta 8 in Docker doesn't start

    Essentially, Docker is forwarding requests to your container on the 0.0.0.0 network interface, but Kestrel is only listening on localhost by default.

    So yes, the requests are being passed off to your docker container, but they are not being accepted by the Kestrel webserver. For that reason, you need to override the server.urls property as others have posted:

    ENTRYPOINT ["dnx", "web", "--server.urls", "http://0.0.0.0:5000"]
    

    You should then see:

    Now listening on: http://0.0.0.0:5000
    

    when running your container. You can also do a quick docker ps command to verify that 0.0.0.0 is in fact the network interface that Docker is forwarding requests for.

    I also wrote a bit about how to get ASP.NET 5 running on Docker on Windows - it's a bit more involved since not only does Docker have to forward requests to the container, but we have to get VirtualBox to pass off requests to the Docker virtual machine boot2docker (typically called default in Virtual Box) before Docker can hand them off to our container.

    Post is here: http://dotnetliberty.com/index.php/2015/10/25/asp-net-5-running-in-docker-on-windows/

    0 讨论(0)
  • 2020-12-17 02:23

    For a more complete understanding of your app environment, please post your project.json file and the beta version of ASP.net you are working with.

    For now you can try cleaning up your Dockerfile by taking out "project.json" and "-p" arguments from the ENTRYPOINT instruction, remove tcp from the EXPOSE command, and finally, specify the "--server.urls" argument in the ENTRYPOINT instruction so that it uses 0.0.0.0 instead of the default localhost as follows:

    FROM microsoft/aspnet
    
    COPY . /project        
    WORKDIR /project       
    RUN ["dnu", "restore"]
    
    EXPOSE 5000
    
    ENTRYPOINT ["dnx", "web", "--server.urls"]
    

    Alternatively, you can try dropping the EXPOSE command altogether and expose the docker port, 5000, in the ENTRYPOINT instruction as follows:

    FROM microsoft/aspnet
    
    COPY . /project        
    WORKDIR /project       
    RUN ["dnu", "restore"]
    
    ENTRYPOINT ["dnx", "web", "--server.urls", "http://0.0.0.0:500"]
    

    Either way you would then build your container and run it using something like the following:

    $ docker run -it -p 80:5000 myapp
    
    0 讨论(0)
提交回复
热议问题