microsoft / iis-docker

Dockerfile for IIS
https://hub.docker.com/r/microsoft/iis/
MIT License
293 stars 129 forks source link

APPCMD failed with error code 4312 #157

Closed dropsonic closed 5 years ago

dropsonic commented 5 years ago

I have a very simple image with ASP.NET application:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-1803
RUN Install-WindowsFeature MSMQ-Server
ENV CONNECTION_STRING=empty
RUN md C:\Customization; md C:\Snapshots; md C:\Backup
COPY ./Site/ /inetpub/wwwroot

I create a container with this command: docker run -p 8085:80 --name test1 myimage -e CONNECTION_STRING='Data Source=(local);Initial Catalog=mydb;User Id=sa;Password=mypass'

But it immediately stops with the following error:

 Service 'w3svc' has been stopped

APPCMD failed with error code 4312

Failed to update IIS configuration

Please advise why I receive this error.

bariscaglar commented 5 years ago

You have two problems with your approach. First one is myImage needs to come last, after the environment variables. You also need double quotes around your connection string as it has spaces. This has worked successfully on my machine:

docker run -p 8085:80 --name test1 -e CONNECTION_STRING="Data Source=(local);Initial Catalog=mydb;User Id=sa;Password=mypass" myimage

deedubb commented 1 year ago

Since I tracked this down I thought I'd share... ServiceMonitor by default starts DefaultAppPool, if you delete the defaultAppPool and intend to use a different name, then you get this error. To solve it/workaround you need to pass the correct app pool name... Yeah, after spending 40 minutes on this I ran the command with no arguments and had my answser.

USAGE: C:\ServiceMonitor.exe [windows service name]
       C:\ServiceMonitor.exe w3svc [application pool]

Options:
    windows service name    Name of the Windows service to monitor
    application pool        Name of the application pool to monitor; defaults to DefaultAppPool