Installing msi on a docker container - .net

Need help with dockerizing legacy application
I have a legacy app which contains multiple components(msi installers). These components use variety of technologies like C#, windows forms, C++, MFC, .net remoting, C# webservices(asmx). Out of these components a couple of them are desktop ui applications.
I was researching the feasibility of dockerizing these components. I am aware that it is not possible to display UI from docker containers, but the UI components also have a command-line counterpart using which we can perform all the operations which can be done with UI.
I started with a simple component. This contains asmx web services developed in C# and is generally hosted on IIS on a windows machine.
It installs its files into the following locations
C:\program Files\ ==> configurable
C:\programData\
I created the docker file with following actions
take a windows server core image and enable iis and other
dependencies
Copy the installer from host machine to the container
Run the installer in silent mode using msiexec command.
When I run docker build command using this docker file, I am getting an error Could not access network location "C:\Program Files\\
No help from google.
Can anybody help me in getting around the issue.
I have a couple of questions
1. Does a docker container by default contain default windows directories like program files, program files(x86), user profile, Program data and app data?

I've done similar work 2 years ago, dockerizing some C# code we had in our organisation.
Here's a snippet from one of the Dockerfile that should help you achieve what you are trying to do -
FROM microsoft/windowsservercore
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
#Copy installers
RUN (New-Object System.Net.WebClient).DownloadFile('https://download.microsoft.com/download/B/4/A/B4A8422F-C564-4393-80DA-6865A8C4B32D/MicrosoftAzureAuthoringTools-x64.msi', 'c:\tools\MicrosoftAzureAuthoringTools-x64.msi') ;\
(New-Object System.Net.WebClient).DownloadFile('https://download.microsoft.com/download/B/4/A/B4A8422F-C564-4393-80DA-6865A8C4B32D/MicrosoftAzureLibsForNet-x64.msi', 'c:\tools\MicrosoftAzureLibsForNet-x64.msi') ;\
Start-Process 'msiexec' -ArgumentList '/i c:\tools\MicrosoftAzureAuthoringTools-x64.msi /quiet /qn /norestart /log c:\tools\installAuth.log'; \
Start-Sleep -s 30 ;\
Start-Process 'msiexec' -ArgumentList '/i c:\tools\MicrosoftAzureLibsForNet-x64.msi /quiet /qn /norestart /log c:\tools\installLib.log';\
Start-Sleep -s 30 ;\
Remove-Item c:\tools\*.msi -force
My example downloads the files from the internet, then installs it from the c:\tools folder to which they were downloaded to, but it should work just as well and also eliminates dependency on files existing on the host machine.
Hope it helps.

Related

Deploy .Net 4.5 WebApi project with WebDeploy using Docker

I am new to docker and trying to learn .Net 4.5 applications to go with Docker Windows Container on our on-premise data center.
I followed link [http://fluentbytes.com/deploying-asp-net-4-5-to-docker-on-windows/#comment-530794][1]
Following is my dockerfile for getting necessary docker images all is good:
# GET BASE IMAGE
FROM microsoft/windowsservercore
RUN dism /online /enable-feature /all /featurename:iis-webserver /NoRestart
# GET IIS IMAGE
FROM windowsserveriis
RUN dism /online /enable-feature /all /featurename:IIS-ASPNET45
# GET WEB DEPLOY INSTALLED
FROM windowsserveriisaspnet
RUN mkdir c:\install
ADD WebDeploy_2_10_amd64_en-US.msi /install/WebDeploy_2_10_amd64_en-US.msi
WORKDIR /install
RUN powershell start-Process msiexec.exe -ArgumentList '/i
c:\install\WebDeploy_2_10_amd64_en-US.msi /qn' -Wait
Now the Problem: I use web deploy to create zipped folder, paramerter files and windows script command and then use ANOTHER DOCKER file to deploy my webapi and it is as follows:
FROM windowsserveriisaspnetwebdeploy
RUN mkdir c:\webapplication
WORKDIR /webapplication
ADD InventoryService.zip /Default\Web\Site/InventoryService.zip
ADD InventoryService.deploy.cmd Default\Web\Site/InventoryService.deploy.cmd
ADD InventoryService.SetParameters.xml
Default\Web\Site/InventoryService.SetParameters.xml
RUN InventoryService.deploy.cmd, /Y
and it fails with "InventoryService.deploy.cmd" is not recognized as an internal or external command, operable program or batch file.
I spent a lot of hours googling and stackoverflowing but to no avail. Can you please throw some light on
How we will deploy webapi with .net 4.5" using container?
what I am doing wrong in above dockerfile?
I will like to deploy this webapi to use given port (i.e. 12345 and not 80), so how will we have to do it?
Your help will be really appreciated!!

How to install Tomcat in Docker Windows Server Container?

On my windows server 2016 tp5 virtual machine, I would like to create a simple native windows based docker example without virtualbox.
The example needs tomcat for windows and since this windows server 2016 docker container uses a shared windows kernel, installing tomcat should be straight forward, alas! Using the following powershell docker build command stops with non-zero code: 255
Dockerfile in c:\build:
FROM microsoft/windowsservercore
RUN powershell -Command wget -Uri mirror.klaus-uwe.me/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70-windows-x64.zip -OutFile "$env:TEMP\tomcat-7.0.70.zip"
Admin-powershell:
docker build c:\build
Result:
---> Running in 317a3572890e
The command 'cmd /S /C powershell -Command wget -Uri mirror.klaus-uwe.me/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomca
t-7.0.70-windows-x64.zip -OutFile "$env:TEMP\tomcat-7.0.70.zip"' returned a non-zero code: 255
Although the zip file has been downloaded in my users temp dir.
Can anybody tell me, how a native windows tomcat installation should look like, as I am not really deep in this stuff.
As mentioned here:
The error code "255" usually means that it is not able to find the file you are asking it to execute
So try and test with the full path and name of the binary(ies) involved in your RUN command line (like powershell)
But test also a simpler case:
RUN dir c:\Users\
This has been recently reported as failing with the same exit code 255, which would mean the latest docker on Windows Server 2016 Technical Preview 5 has a bug.

How to execute a PostGre exe file with silent mode?

Hy,
I would install PostGreSQL 9.1 on a Windows Server 2012.
I want to used a PowerShell script.
With my JDK executables file, I use Start-Process "Myfile" -ArgumentList "/s" -Wait
But the argument \s don't work with my PostGre executables file.
Have you an idea ?
You can use Install-Postgres Powershell module, it's on TechNet Gallery.
The Install-PostgreSQL PowerShell module does the following:
creates a local windows user that PostgreSQL will use
downloads the PostgreSQL installer provided by EnterpriseDB
installs Postgres unattended using the supplied parameters
sets postgres windows user as owner of Postgres files and folders
sets Postgres windows service to run under postgres local user
creates pgpass.conf file in AppData
copies configuration files to data directory
opens the supplied port that PostgreSQL will use in the Windows
Firewall
Usage
Import-Module Install-Postgres
Install-Postgres -User "postgres" -Password "ChangeMe!"
I have used this command : Start-Process $installFile -ArgumentList "--unattendedmodeui minimal --mode unattended --prefix $dest --datadir $dest\data --servicepassword $pwd" -Wait
Thanks for your help ! :)

Batch script not doing anything when execute from remote machine using ssh

i'm having a problem while executing batch script from linux machine.
Scenario:
I've a windows machine installed server2008, I need to automate some windows task that executes from linux machine. I've installed cygwin software on windows VM and create a batch script that is running fine from cygwin terminal. i.e cd ~/;./script.bat
Problem:
When I execute the same script from linux machine using ssh it seems works fine and print script executed successfully but when I checked that the task from windows it did nothing.
cat script.bat
#echo off
set sourcePasswd=%1
set destinationPasswd=%2
set destinationProjectName=%3
set user=%4
set xmlPath=C:\cygwin\home\%user%\Duplicate.xml
ECHO Start : Duplication project source for %destinationProjectName%
"C:\Program Files (x86)\Common Files\MySoftware\Duplicate.EXE" -f %xmlPath% -sp %sourcePasswd% -dp %destinationPasswd% -sup -md -dn %destinationProjectName%
ECHO Finish : Duplication project source for %destinationProjectName%
Looks like Leopard hasn't been back since he posted the question or the link to the answer, so I'll be the Point Pimpette tonight and fill in the blank.
The answer below is from the link:
http://cygwin.com/ml/cygwin/2010-07/msg00598.html
It was fixed after doing the following setup :
Open control panel=> Administrative Tools=>Computer
Management=>Services
lookup the sshd service, right
click=>properties=>log on, and check the checkbox for Allow service
to interact with desktop
restart the service.
thanks
Saravana

Add nginx.exe as Windows system service (like Apache)?

I set up NGINX as a front end server for static content and I use Apache as a back-end server for other thing.
The thing is I can't find a logical answer that allows me to make nginx.exe a Windows system service (like my Apache).
Any come across an answer to this?
How to do it with Windows Service Wrapper
(Note: There are promising alternatives by now - see also NSSM solution described in answer below from Adamy.)
Download the latest version of Windows Service Wrapper via github or nuget.
Current version as of this writing is v2.2.0
Since v2.x executables for .NET2.0 and .NET4.0 are available - others only on demand.
Rename winsw-*.exe to something like nginxservice.exe.
This is the name that will show up for the process that owns your nginx process.
Place an XML file next to the exe with the same base name, e.g. nginxservice.xml. The contents should be like below (verify your nginx location).
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<executable>c:\nginx\nginx.exe</executable>
<logpath>c:\nginx\</logpath>
<logmode>roll</logmode>
<depend></depend>
<startargument>-p</startargument>
<startargument>c:\nginx</startargument>
<stopexecutable>c:\nginx\nginx.exe</stopexecutable>
<stopargument>-p</stopargument>
<stopargument>c:\nginx</stopargument>
<stopargument>-s</stopargument>
<stopargument>stop</stopargument>
</service>
You can find up to date details about the configuration on the config github page, a generic example showing all possible options here and an installation guide.
Run the command nginxservice.exe install as administrator.
You will now have an nginx service in your Services! (It is set to start automatically on boot; if you want to start your server, you must manually start the service (net start nginx).)
Detailed description of correctly setting up nginx as a Windows Service:
http://web.archive.org/web/20150819035021/http://misterdai.yougeezer.co.uk/posts/2009/10/16/nginx-windows-service/
Additional info not contained in above blog post:
You can find the latest version of the Windows Service Wrapper also via this Maven Repository:
http://repo.jenkins-ci.org
Examples for Maven + Gradle:
<dependency>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<version>2.2.0</version>
<classifier>bin</classifier>
<packaging>exe</packaging>
</dependency>
<repository>
<id>jenkinsci</id>
<name>jenkinsci-releases</name>
<url>http://repo.jenkins-ci.org/releases</url>
</repository>
compile "com.sun.winsw:winsw:2.2.0"
repositories {
mavenCentral()
maven { url http://repo.jenkins-ci.org/releases }
}
Download NSSM form
http://nssm.cc/download .
"Run %NSSM_HOME%\nssm.exe install “Nginx”"
Select the Nginx executable in the NSSM dialog, then OK.
Go to Services and start the new created service "Nginx", done.
SC.EXE will only work for executables that already support the Windows Services API and can respond properly to start and stop requests from the Services Control Manager (SCM). Other regular applications, not specifically written as a service, will simply fail to start (usually with error 1053)...
For those exe's, you need a "service wrapper" -- a small utility that can accept the start/stop commands from the SCM and run/terminate your application accordingly. Microsoft provides Srvany (which is free yet very basic), but there are several other free and commercial alternatives.
BTW, you should check out this guide showing how to run Nginix as a service, especially step 7 which discusses how to stop Nginix properly. Not every wrapper will support that functionality (Srvany doesn't)...
You can using start.bat and stop.bat to realize the same effect.
start.bat
#ECHO OFF
REM Start Nginx
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF NOT "%ERRORLEVEL%"=="0" (
REM Nginx is NOT running, so start it
c:
cd \nginx
start nginx.exe
ECHO Nginx started.
) else (
ECHO Nginx is already running.
)
stop.bat
#ECHO OFF
REM Stop Nginx
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
IF "%ERRORLEVEL%"=="0" (
REM Nginx is currently running, so quit it
c:
cd \nginx
nginx.exe -s quit
ECHO Nginx quit issued.
) else (
ECHO Nginx is not currently running.
)
The easiest way I've found, was using the Chocolatey package manager.
Once Chocolatey is installed, you open an administrative prompt and type:
choco install nginx
You now have a Windows service named 'nginx' running.
Download zip file from here.
Extract nginx-service.exe from winginx\build and run it.
Official nginx wiki referes on winginx for this purpose. It builds exe-installer in linux environment.
Process looks like this:
sudo apt-get install nsis make
wget https://github.com/InvGate/winginx/archive/master.zip
unzip master.zip
cd winginx-master/
make
ls -lh ./build/nginx-service.exe
To get actual versions you should specify them in Makefile.
NSSM is the best tool to run Nginx as a service.
If you do not want to use any external 3rd party software then you can implement any of these two methods.
Windows Task Scheduler
Windows startup shortcut
Windows Task Scheduler
As mentioned in this answer prepare one start.bat file.
Put this file where nginx.exe is present.
Open windows task scheduler and set up the task as described in this answer to run it indefinitely.
Do not forget to run this task as the highest privilege with the system account, more details can be found here.
Make the task to start daily at a certain time, through the bat file it will check whether the service is already running to avoid creating multiple nginx.exe instances.
If due to some reason Nginx shuts down, within 5 minutes it will start.
Windows Startup shortcut
Create one shortcut of nginx.exe and put it in the startup folder of Windows.
Follow this answer to find your startup location.
Nginx will run automatically whenever you log in to the system.
This one is the easiest. However, it is dependent on user profile i.e. if you are running Nginx on a server, it will run only for your user account, when you log off it stops.
This is ideal for dev environment.
Rather than turning nginx into a service, or using CMD to start a process, which really doesn't seem to work. I found that Powershell makes it easy to startup nginx as a detached process. I've combined starting nginx with PHP. Below is the script, named "start-nginx.ps1"
$fcgiPort = "127.0.0.1:9000"
$PHPini = "c:\php\php.ini"
$ErrorActionPreference = "SilentlyContinue"
function restart {
Push-Location /nginx
Stop-Process -Force -Name nginx
Start-Process ./nginx.exe -WindowStyle Hidden
Stop-Process -Force -Name php-cgi
Start-Process "c:\php\php-cgi.exe" -ArgumentList ("-b" + $fcgiPort + " -c " + $PHPini) -WindowStyle Hidden
Pop-Location
}
restart
This script can be executed from any directory, but needs to be customized for where your nginx installation is located.
This script includes a silent attempt to kill nginx and PHP before launching both.
Windows systems are supposed to recognize ".ps1" files as powershell, even in the CMD prompt.
I created another small script to kill the running processes, which simply removes the "start-process" lines from this file.
To run at startup, I used the win-R command to navigate to the directory shell:startup
Placing a shortcut to the startup script in this directory, nginx starts at boot!
Powershell also includes a much more sophisticated ability to schedule tasks, and it is possible to schedule this script to run at startup. See This Link
From the article:
>powershell
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:30
Register-ScheduledJob -Trigger $trigger -FilePath $HOME/start-nginx.ps1 -Name startNginx
Combined, I think this approach gets you everything you'd need from an nginx windows service and doesn't require any third-party applications.

Resources