Problem running MVC app. in container - no IIS application?

Hi All,

I’m pretty new to docker. I’m trying to run an MVC web app. in a container on Docker for Windows Desktop (Community version 2.0.0.2). This is on a Windows 10 system.

The steps I use to build the image are:

Docker file:
FROM microsoft/aspnet
COPY ./ /inetpub/wwwroot/MC_v2

build command:
docker build -t mcv2 .

The run command is:
docker run --rm -d -p 8081:80 --name MCV2 mcv2

All pretty simple. The container starts, but when I go to the URL (http://localhost:8081/MC_v2/) I get the configuration error:
It is an error to use a section registered as allowDefinition=‘MachineToApplication’ beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

It gives web.config Line: 28 as the offending line:
<authentication mode="Windows" />
Normally I would configure the site for Anonymous Authentication and Allow all users in .Net authorization and in fact the site is working that way on my local machine. The error suggests to me that the location /MC_v2 is not configured as an application when it is running in the docker container.
But how do I do that? Is there a way in the dockerfile to do that? Or is there another issue here that I am missing?

Cheers,
Geoff

By no means am i an expert with the IIS container - but as far as i knowits not domain joined so there is no way that i will be able to run windowsauthentication. It doesn’t appear though that is you main issue, could isuggest that you switch to anonymous authentication while you are tryingto debug the application

What version of MVC are you trying to run in a container?

Hi jderonde,
Thanks for the speedy reply.
It is already set to anonymous in the working local site:

image

I understand that integrated windows authentication won’t work here (there is an horrendously complex way to achieve that, but I’m at the level of baby steps right now).

This is MVC 5.2.3.0 (would have pasted a pic of the System.Web.Mvc.dll properties, but new users are only allowed 1 image per post).

Cheers,
Geoff

Could you try changing your web.config entry to<authentication mode="Forms">

Hi,
The application is not configured for that, but I tried anyway. The error is the same.
I verified that web.config in the running container did actually change.

Cheers,
Geoff

Hi,
I found the answer.
I attached a CMD to the running container and executed the following to create the application:

appcmd.exe set config -section:system.applicationHost/sites /+"[name='Default Web Site'].[path='/MC_v2']" /commit:apphost
appcmd.exe set config -section:system.applicationHost/sites /+"[name='Default Web Site'].[path='/MC_v2'].[path='/',physicalPath='C:\Inetpub\wwwroot\MC_v2']" /commit:apphost

The site now works with no authentication. I guess most examples assume you will create the site in the root of the default web site. So this might not be necessary then. I’m thinking it must be possible to add these commands to the dockerfile somehow.

Onwards to Integrated Windows Authentication.

Cheers,
Geoff

One last point here. There is not much on running appcmd inside a dockerfile out there yet.
So to save some pain for anyone following, this is what the dockerfile looked like (no windows integration yet though).

Cheers,
Geoff

# escape=`
FROM microsoft/aspnet

COPY ./ /inetpub/wwwroot/MC_v2

RUN c:\Windows\System32\inetsrv\appcmd.exe add app /site.name:'Default Web Site' /path:/MC_v2 /physicalPath:C:\Inetpub\wwwroot\MC_v2
1 Like

You saved me! <3
Thanks!