Closed JohanSpannare closed 6 years ago
if executed during build of image.
You mean within the docker file the calls to those Cmdlets fail? @mcy94w please take a look.
Yes, if you try execute the commands in the dockerfile (docker build)
Can you please share your dockerfile?
Hi @JohanSpannare :
I tried the command
remove-IISSIte -name 'Default Web Site' -confirm:$false;
and
Start-IISSite -name 'Default Web Site';
And they both worked. Could you please share you dockerfile so we can repro the issue?
Thanks
I am on vacation at.m, i will post the Dockerfile when i am back ~20:e July
Please reopen with the additional information.
Here is an example:
# escape=`
FROM microsoft/iis:nanoserver-sac2016
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG SITENAME
#Not Working
RUN Import-module IISAdministration; `
Remove-IISSite -Name 'Default Web Site' -Confirm; `
docker build --build-arg SITENAME=TestSite . Sending build context to Docker daemon 4.096kB Step 1/4 : FROM microsoft/iis:nanoserver-sac2016 nanoserver-sac2016: Pulling from microsoft/iis Digest: sha256:1914f6fa5a3f4bced7f18a857c452df859c5f246bb11e2d107991daab6492549 Status: Downloaded newer image for microsoft/iis:nanoserver-sac2016 ---> a6bfaba3775b Step 2/4 : SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] ---> Using cache ---> cfda0faf5a45 Step 3/4 : ARG SITENAME ---> Using cache ---> 9db2195040ec Step 4/4 : RUN Import-module IISAdministration; Remove-IISSite -Name 'Default Web Site' -Confirm; ---> Running in 58b60e743810 Remove-IISSite : Object reference not set to an instance of an object. At line:1 char:109
+ CategoryInfo : NotSpecified: (:) [Remove-IISSite], NullReferenc
eException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.IIS.Powe
rshell.Commands.RemoveIISSiteCommand
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Import-module IISAdministration; Remove-IISSite -Name 'Default Web Site' -Confirm;' returned a non-zero code: 1
If i do this manually it works.
docker run -it --entrypoint powershell -t microsoft/iis:nanoserver-sac2016
Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved.
PS C:> Import-module IISAdministration PS C:> Remove-IISSite -Name 'Default Web Site' -Confirm -Verbose
Confirm Are you sure you want to perform this action? Performing the operation "Remove-IISSite" on target "Default Web Site". [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): VERBOSE: Web site 'Default Web Site' successfully deleted. PS C:>
I can confirm that the -confirm:$false solves the "Remove-IISSite : Object reference not set to an instance of an object." error.
Havent tried start and stop sites yet.
Same happens to me!
It's weird, this command works flawlessly:
Get-IISConfigSection -SectionPath "system.webServer/defaultDocument" | Get-IISConfigCollection -CollectionName "files" | New-IISConfigCollectionElement -ConfigAttribute @{"Value" = "MyDefDoc.htm"};
However this one needs the -confirm:$false
Get-IISConfigSection -SectionPath "system.webServer/defaultDocument" | Get-IISConfigCollection -CollectionName "files" | Remove-IISConfigCollectionElement -ConfigAttribute @{"Value" = "iisstart.htm"} -confirm:$false;
Remove-IISSite -Name 'Default Web Site' is not working if executed during build of image. However Remove-WebSite -Name 'Default Web Site' works fine.
Same for Start-IISSite and Stop-IISSite.
Errors: [2018-04-25 15:15] Spännare, Johan: Start-IISSite : The object identifier does not represent a valid object. (Exception from HRESULT: 0x800710D8) At line:1 char:170
Best reg Johan