7
votes

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 dockerfile looks like this:

FROM microsoft/aspnet

COPY . /app
WORKDIR /app
RUN ["dnu", "restore"]

EXPOSE 5000/tcp
ENTRYPOINT ["dnx", "-p", "project.json", "web"]

I then ran docker build -t myapp . and then docker run -d -p 80:5000 myapp it says it is running but I cannot open the website in the browser. I know on Windows you are supposed to find the ip address that the actual virtual machine is running against by using docker-machine ip default which ended up being 192.168.99.100 but when I navigated to http://192.168.99.100 I just get the generic "This webpage is not available" error message. I have also tried different variations of this docker run command, such as docker run -it -p 80:5000 myapp, docker run -p 80:5000 myapp, and I have also tried different ports, such as docker run -d -p 5000:5000 myapp but nothing seems to work.

I have tried this both on my windows machine and on my linux server, but they both do not work.

I am able to run dnx web without docker and everything works as expected.

4
Are you using virtualbox or something like that? Or is it a proper server install?RubbleFord

4 Answers

6
votes

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/

3
votes

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
2
votes

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();
    }
}
1
votes

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.