Trying to update IIS authentication settings using Powershell.
Here's the dockerfile:
FROM microsoft/aspnet
SHELL ["powershell"]
WORKDIR C:\MyWebApp
RUN Import-Module WebAdministration; `
New-WebApplication -Name 'MyWebApp' -Site 'Default Web Site' -PhysicalPath C:\MyWebApp -ApplicationPool DefaultAppPool; `
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/anonymousAuthentication" -Name Enabled -Value False -PSPath IIS:\ -Location "'Default Web Site/MyWebApp'"; `
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/basicAuthentication" -Name Enabled -Value False -PSPath IIS:\ -Location "'Default Web Site/MyWebApp'"; `
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/windowsAuthentication" -Name Enabled -Value True -PSPath IIS:\ -Location "'Default Web Site/MyWebApp'"; `
Set-WebConfigurationProperty -Filter "/system.web/identity" -Name impersonate -Value True -PSPath IIS:\ -Location "'Default Web Site/MyWebApp'"; `
Set-ItemProperty -Path IIS:\AppPools\DefaultAppPool\ -Name managedPipelineMode -Value 0; `
Set-ItemProperty -Path IIS:\AppPools\DefaultAppPool\ -Name enable32BitAppOnWin64 -Value True;
Set-WebConfigurationProperty is causing W3SVC to get stopped and container exits.
PS C:\Projects\docker_workspace\app> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
96bc3c60e9df wcpapp:v1 "C:\\ServiceMonitor.e…" About a minute ago Exited (2147500037) 12 seconds ago
PS C:\Projects\docker_workspace\app> docker logs 96
Service 'w3svc' has been stopped
ERROR: Failed to start or query status of service 'w3svc' error [80004005]
Service 'w3svc' has been stopped
If I remove Set-WebConfigurationProperty statements, Container stays up and running. What am I missing here?
Related
For my projects I sometimes need to unittest my code against a ms sql server.
At the moment, I created a monstrous docker image, containing all the tools I need, including the sql server.
Now this image got to about 15 GB in size, which is really not cool.
So I'm trying to use the GitLab CICD Service part (as described here https://docs.gitlab.com/ee/ci/services/index.html).
But when I'm trying to add my (custom) image as a service I keep getting the health check issue:
*** WARNING: Service runner-hrtjgacu-project-1489-concurrent-0-2ae3f3cd2099f19a-gitlab.mydomain.lcaol__windowsdockerimages__mssql-0 probably didn't start properly.
Health check error:
service "runner-hrtjgacu-project-1489-concurrent-0-2ae3f3cd2099f19a-gitlab.mydomain.local__windowsdockerimages__mssql-0-wait-for-service" health check: exit code 1
Health check container logs:
2023-01-19T09:58:09.913696500Z FATAL: No HOST or PORT found
Service container logs:
*********
Now I found something online about needing to expose the ports of the service in the Dockerfile, so I tried that, but that did not help.
This is what my MSSQL DockerFile currently looks like:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# Download Links:
ENV exe "https://go.microsoft.com/fwlink/?linkid=840945"
ENV box "https://go.microsoft.com/fwlink/?linkid=840944"
ENV sa_password="_" \
attach_dbs="[]" \
ACCEPT_EULA="Y" \
sa_password_path="C:\ProgramData\Docker\secrets\sa-password"
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# make install files accessible
COPY start.ps1 /
WORKDIR /
RUN Invoke-WebRequest -Uri $env:box -OutFile SQL.box ; \
Invoke-WebRequest -Uri $env:exe -OutFile SQL.exe ; \
Start-Process -Wait -FilePath .\SQL.exe -ArgumentList /qs, /x:setup ; \
.\setup\setup.exe /q /ACTION=Install /INSTANCENAME=MSSQLSERVER /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS ; \
Remove-Item -Recurse -Force SQL.exe, SQL.box, setup
RUN stop-service MSSQLSERVER ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.MSSQLSERVER\mssqlserver\' -name LoginMode -value 2 ;
HEALTHCHECK CMD [ "sqlcmd", "-Q", "select 1" ]
EXPOSE 1433/tcp
EXPOSE 4022/tcp
EXPOSE 135/tcp
EXPOSE 1434/tcp
EXPOSE 1434/udp
CMD .\start -sa_password $env:sa_password -ACCEPT_EULA $env:ACCEPT_EULA -attach_dbs \"$env:attach_dbs\" -Verbose
And this is is my .gitlab-ci.yml file:
default:
image:
name: gitlab.mydomain.local:4567/windowsdockerimages/basicnetframeworkimage:latest
tags:
- windows
- docker
# The stages during this build
stages:
- build
build:
stage: build
script:
- echo "Hello world"
- ping mssql
- dotnet run
services:
- name: gitlab.mydomain.local:4567/windowsdockerimages/mssql
alias: mssql
Anyone who can help me get closer to the solution?
*Note, the ping mssql also fails, the container in which we run cannot find the DNS
entry
I would use an existing official image for MSSQL server (https://hub.docker.com/_/microsoft-mssql-server) and run unit tests in one container and the database in another one.
I have to create windows container image with our application installed. Our application is a legacy one and it uses hostname in several places during installation. The docker build command doesnot have an option to pass the hostname. So, we are currently stuck at a point where when we run a container with the image created, our application fails to run as its expecting the hostname to be the generated name during the image creation time and not the one we pass with docker run command.
I tried to change the hostname within the container before installing our application using suggestions in this query.But,it did not work.
I wanted to understand if there is a way we can change the hostname from within the windows container?
The following worked for me -
rename-computer.ps1:
$ComputerName = "New Name"
Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname"
Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname"
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\Computername" -name "Computername" -value $ComputerName
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername" -name "Computername" -value $ComputerName
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" -value $ComputerName
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" -value $ComputerName
Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AltDefaultDomainName" -value $ComputerName
Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultDomainName" -value $ComputerName
Dockerfile:
COPY "rename-computer.ps1" "C:/"
RUN powershell -command "Set-ExecutionPolicy RemoteSigned" \
&& powershell -command "C:/rename-computer.ps1 ; hostname" \
&& powershell -command "Set-ExecutionPolicy Restricted" \
&& <your installer runs here>
Sources -
https://serverfault.com/a/731832/845133
https://gist.github.com/timnew/2373475
Good morning.
I am working with Docker for Windows 19.03.8, build afacb8b; running on Windows Server 2019 (10.0.17763.1039)
when I run Docker-Compose up -dV it says something like:
Creating network "docker_default" with the default driver
Creating docker_python-base_1 ... done
Creating docker_msbuild_1 ... done
but when I then use Docker-Compose exec, it says:
ERROR: No container found for msbuild_1
in other words, the UP and the EXEC are not using the same (default?) container name.
Al-waleed Shihadeh asked for more info (thanks you !!!!). so....
my docker-compose.yml file:
version: '3.7'
services:
python-base-srv:
build:
context: ./images/python-base
dockerfile: Dockerfile-PythonBase
image: mycompany/builds-win-base-python:3.7.6
volumes:
- ../../..:C:/bldroot
command: powershell -NoExit -NonInteractive
msbuild-srv:
build:
context: ./images/msbuild
dockerfile: Dockerfile-msbuild
image: mycompany/builds-win-msbuild:15.0
volumes:
- ../../..:C:/bldroot
depends_on:
- python-base-srv
command: powershell -NoExit -NonInteractive
Dockerfile-msbuild:
# escape=`
ARG FROM_IMAGE=mycompany/builds-win-base-python
FROM ${FROM_IMAGE} AS build
SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
RUN Invoke-WebRequest 'https://aka.ms/vs/15/release/vs_buildtools.exe' -OutFile C:\Downloads\vs_buildtools.exe -UseBasicParsing ; `
Start-Process -FilePath 'C:\Downloads\vs_buildtools.exe' -Wait `
-ArgumentList `
'--quiet', `
'--norestart', `
'--locale en-US', `
'--installPath C:\BuildTools', `
'--nocache', `
'--addProductLang en-US', `
'--add Microsoft.Net.Component.3.5.DeveloperTools', `
'--add Microsoft.Net.Component.4.5.TargetingPack', `
'--add Microsoft.Net.ComponentGroup.4.6.1.DeveloperTools', `
'--add Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools', `
'--add Microsoft.Net.ComponentGroup.TargetingPacks.Common', `
'--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP' ; `
Remove-Item c:\Downloads\vs_buildtools.exe -Force
RUN $PATH = $env:PATH + ';C:\BuildTools\MSBuild\15.0\Bin' ; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $PATH
# Start developer command prompt before running the specified command (from RUN/EXEC commandline)
COPY ["VsDevCmdPowerShell.bat", "C:\\BuildTools\\"]
ENTRYPOINT ["cmd", "/k", "C:\\BuildTools\\VsDevCmdPowerShell.bat"]
Dockerfile-PythonBase:
# escape=`
ARG FROM_IMAGE=mcr.microsoft.com/windows/servercore:ltsc2019
FROM ${FROM_IMAGE} AS python-base
SHELL [ "powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';" ]
RUN `
New-Item -Path C:\Downloads -ItemType Directory ; `
New-Item -Path C:\path -ItemType Directory ; `
`
$PATH = 'C:\path;' + $env:PATH ; `
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $PATH ; `
`
Invoke-WebRequest 'https://www.python.org/ftp/python/3.7.6/python-3.7.6.exe' -OutFile c:\Downloads\python-installer.exe -UseBasicParsing ; `
Start-Process c:\Downloads\python-installer.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; `
Remove-Item c:\Downloads\python-installer.exe -Force
CMD ["powershell", "-NoExit", "-NoLogo", "cmd", "/c ver", ";", "python", "--version", ";", "nuget", "help | select -First 1", ";"]
Outputs:
C:\work\docker> docker-compose up -dV msbuild-srv
Recreating docker_python-base-srv_1 ... done
Recreating docker_msbuild-srv_1 ... done
C:\work\docker> docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------
docker_msbuild-srv_1 cmd /k C:\BuildTools\VsDev ... Exit 0
docker_python-base-srv_1 powershell -NoExit -NonInt ... Exit 0
C:\work\docker> docker logs docker_msbuild-srv_1
Call VsDevCmd.bat to setup environment . . .
C:\>call C:\BuildTools\Common7\Tools\VsDevCmd.bat
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
powershell -NoExit -NonInteractive
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\>
C:\>
C:\work\docker>
so - it is not leaving the containers running in the compose UP step like it should.
docker run -it works fine:
docker container run -it --name msbuildTesting -v C:/work:C:/bldroot -w c:\bldroot\build mycompany/builds-win-msbuild
it seems that your containers are exiting directly after docker-compose up, you can verify this by issuing these commands
docker-compose ps
or
docker ps -a
you also can check the reason why the containers exited by checking the logs
docker logs ${container_name}
Notes:
1. You should use this command to connect to the container docker-compose exec msbuild ${command}
i have a windows application which I want to containerize. Its a windows desktop application (not web application). I did some searching and found very little about containerizing desktop application. The application which I want to containerize works fine on WindowsServerCore. I have Windowsservercore image on my machine.
I want to know how can I go about containerizing it. Any documentation or useful videos are available?
when i completed dockerfile can i interact with my application gui??? how???
You can find tons of example of WindowsServiceCore-based applications in StefanScherer/dockerfiles-windows
You need to write a Dockerfile (like for instance diskspd/Dockerfile where you copy/unzip/install the application you need.
FROM microsoft/windowsservercore:10.0.14393.1770
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENV DISKSPD_VERSION 2.0.17
RUN Invoke-WebRequest $('https://gallery.technet.microsoft.com/DiskSpd-a-robust-storage-6cd2f223/file/152702/1/Diskspd-v{0}.zip' -f $env:DISKSPD_VERSION) -OutFile 'diskspd.zip' -UseBasicParsing ; \
Expand-Archive diskspd.zip -DestinationPath C:\ ; \
Remove-Item -Path diskspd.zip ; \
Remove-Item -Recurse armfre ; \
Remove-Item -Recurse x86fre ; \
Remove-Item *.docx ; \
Remove-Item *.pdf
ENTRYPOINT [ "C:\\amd64fre\\diskspd.exe" ]
That being said, a full GUI support for windowscoreserver is still requested:
"Create base container with full GUI support".
I'm trying to run docker command on Windows 10 Enterprise as Admin:
docker-compose exec --user magento2 web find /var/www/sample-data -type d -exec chmod g+ws {} \;
but I got the error:
find: missing argument to `-exec'
I was trying to escape by using '' or "":
docker-compose exec --user magento2 web "find /var/www/sample-data -type d -exec chmod g+ws {} \;"
but it throws anouther error
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:262: starting container process caused "exec: \"find /var/www/sample-data -type d -exec chmod g+ws {} \\\\;\": sta
t find /var/www/sample-data -type d -exec chmod g+ws {} \\;: no such file or directory"
How I can resolve this issue? Normaly when I insert this command inside the container - everything works fine.
Use sh instead:
docker-compose exec --user magento2 web sh -c 'find /var/www/sample-data -type d -exec chmod g+ws {} \;'