Skip to main content

Docker + ASP.NET MVC "Hello world" - abridged edition

Here's the exact steps to get the ASP.NET MVC sample application running in a Docker container in Windows 10, abridged from the Microsoft tutorial here.  I used a fresh Azure VM to avoid the many weird issues I kept running into with my bizarrely-screwy desktop, because of course it is.

$ip = (New-AzureRmVm -Name dockertest -Credential (Get-Credential) | Get-AzureRmPublicIpAddress); "Remote desktop to: " + $ip.IpAddress; mstsc -v $ip.IpAddress

Next, install chocolatey, then install everything else:
choco install visualstudio2017professional visualstudio2017-workload-netweb docker docker-desktop -y
Sign out and back in again, run docker desktop as admin, right-click the tray icon and switch to windows containers, let it enable hyper-v and reboot.  Run docker desktop as admin again.

Open Visual Studio, create a new project using the ASP.NET template and let it add all the MVC stuff.
Create a publish profile, publishing files to the default location of /bin/Release/Publish
Create a file in the project directory called "dockerfile", which should contain this:
FROM microsoft/aspnet
COPY ./bin/Release/Publish/ /inetpub/wwwroot

Open cmd/powershell/whatever and cd over to the directory containing the dockerfile you made earlier, then build your container image and run it:
docker build -t hello-asp .
docker run -d --name hello -p 8080:80 hello-asp
Open a browser to http://localhost:8080, and you're done

(Don't forget to delete that VM afterwards)

In general, Docker has pretty unhelpful error messages, they're usually some version of: "cannot find the file specified", or "the process cannot access the file".  Ignore them and go look for people discussing the error message on Stack Overflow / Github. I guarantee you it'll be some tiny dumb thing like all of the below.

Solutions I came across:
Always run docker as admin, otherwise it'll misbehave in pretty weird ways.
"The daemon is not running" (when it totally is) - exit Docker desktop and re-run as admin.
If a "docker run" command fails with the message "failed to create endpoint on network ... HNS failed with error: the process cannot access the file".  It just means you're reusing a port number that's already used.
Don't put the port number at the end of a "docker run" command or IIS won't start properly
In general if you get weird behaviour, just look very carefully at your parameter formatting, try reordering parameters, you might be surprised how often this is the problem.
To look at output from a container: add the "-it" parameters to a "docker run" command


Popular posts from this blog

"A section using 'configSource' may contain no other attributes or elements" error after installing Application Insights

After installing the Application Insights nuget package to an Umbraco solution, you'll get this error:

A section using 'configSource' may contain no other attributes or elements

<ExamineLuceneIndexSets configSource="config\ExamineIndex.config" />
     <log4net configSource="config\log4net.config">
             <level value="ALL" />
             <appender-ref ref="aiAppender" />
Source File: \project\web.config

This happens because part of the Application Insights installation process adds a <log4net> section to web.config.  Which would make sense, except Umbraco already has a <log4net> section in /config/log4net.config.  So as you can imagine, the solution is to manually move everything its added into that file. Unfortunately you can't just copy/paste the whole lot, but it's not particularly complicated:

Move <appender-ref ref="aiAppender" /> into the lo…

Using WiX to create an event source during install of a .NET framework project

Edit: so I guess I wasn't the only one confused with this stuff, as it's been my most popular post by far!  If I've helped you out or saved you some time, please let me know in the comments :)

In order for this to work, you have to add references to WixUtilExtension and WixNetFxExtension to your WiX project.  Once that's done, add this inside a <Component> element:

<Util:EventSourcexmlns:Util=""Name="EVENTSOURCEGOESHERE"Log="Application"EventMessageFile="[NETFRAMEWORK40FULLINSTALLROOTDIR]EventLogMessages.dll" />
Obviously replace EVENTSOURCEGOESHERE with your event source name.  NETFRAMEWORK40FULLINSTALLROOTDIR is a property set by the WixNetFxExtension which stores the path to the .NET framework v4 directory, but you can replace this with the corresponding property for the directory containing the relevant EventLogMessages.dll file.  So if you're using the .NET framewo…

How to make yourself a Dynamics CRM 2011 Deployment Administrator

Today I needed to deactivate one of our Dynamics organisations, but when I opened the Dynamics Deployment Manager, I received the following error:

"Only the Deployment Administrators are able to use Deployment Manager. You are not a Deployment Administrator."
Bummer. I did a bit of Googling and found this post by Ronald Lemmen (thanks for pointing me in the right direction!).  Since the Dynamics Deployment Manager is obviously checking the MSCRM_CONFIG database for this information I attached a database trace to it and found that it's executing these queries (among many others):

exec sp_executesql N'SELECT  Id, [DefaultOrganizationId], [IsDisabled], [Name]   FROM [SystemUser]   WHERE ((([Name] = @Name0)) ) AND (IsDeleted = 0) ', N'@Name0 nvarchar(41)',@Name0=N'{My windows domain account}'
exec sp_executesql N'SELECT  Id, [Name], [UniqueifierId]   FROM [SecurityRole]   WHERE ((([Name] = @Name0)) ) AND (IsDeleted = 0) ', N'@Name0 nvarchar…