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…

Handling double-quoted CSVs in Azure Data Factory Pipelines

Azure Data Factory by default uses a backslash as the escape character for CSVs, but we ran into an issue with this today processing one of the CSV files from  As with most CSVs they use quotes around values as normal and with double-quotes for empty values, but they also use double-quotes to escape quotes within non-empty values. This probably sounds confusing, so here's an example:

"column 1","column 2","","column 4 value is ""sort of"" like this"

The ADF pipeline failed because the double-quotes don't get escaped correctly:
ErrorCode=UserErrorSourceDataContainsMoreColumnsThanDefined, found more columns than expected column count.

The solution was to change the "Escape character" property on the dataset, by clicking the "Edit" button beneath it and manually entering "", since "" isn't in the list of escape characters.  I didn't think this would work at fir…

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…