ASP.NET Core RC2 running on Docker

To get ASP.NET Core RC2 running on Docker, is very close to RC1 but with a few quirks that I haven't seen any post on.
So I will write here how I got an ASP.NET Core RC2 app running on docker.

First of all you will need your DockerFile mine looks like:

FROM microsoft/dotnet  
# Set environment variables
ENV ASPNETCORE_URLS="http://*:5000"  

# Copy files to app directory
COPY . /app

# Set working directory

# Restore NuGet packages
RUN ["dotnet", "restore"]

# Open up port

# Run the app
ENTRYPOINT ["dotnet", "run"]  

It should be placed beside your .xproj file. When that's done your next step is to modify your Program.cs
And this is the step I couldn't find anywhere else and it have also changed between RC1 to RC2.

This is how my Program.cs looks like:

using System;  
using System.Collections.Generic;  
using System.IO;  
using System.Linq;  
using System.Threading.Tasks;  
using Microsoft.AspNetCore.Hosting;  
using Microsoft.AspNetCore.Builder;

namespace myapp  
    public class Program
        public static void Main(string[] args)
            var host = new WebHostBuilder()


So the change here is that I have added .UseUrls("http://*:5000") cause by default Kestral listning to http://localhost:5000 and that didnt work for me atleast.

When that is done the next step is to build your docker image.

docker build -t myapp .

When that's done next step is to run your docker container.

docker run -t -d -p 5000:5000 myapp

And now you should be able to access your application at http://localhost:5000 , if your running docker for windows (beta).
It will be

Hope this post helps

comments powered by Disqus