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:
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