Docker–How to move container from one Windows host to another

In my article on docker container (https://mdaslam.wordpress.com/2017/05/24/windows-server-2016-docker-container-dockerfile/), I described how to create docker container.

Now docker container is created and you want to migrate/copy it from one windows server machine/host to another.

You cannot copy the running container from one host to another, rather you need to follow the following steps –

  1. Commit it
  2. Export the docker image to the local drive using the command – docker save –o <Path of the output file location> <Image ID or Name> Example – docker save –o “d:\temp\images\dotnetsamples” d242f2db7922
  3. It will copy the image on the given location. In the above example, it will be “d:\temp\images”.
  4. Now copy the above newly exported image to the target windows 2016 server.
  5. Once copied there successfully, load it onto that server using the command – docker load –i <Path of the output file location> Example – docker load –i “d:\temp\images\dotnetsamples”
  6. On the successful execution of the above command, image will be restored successfully. To verify it, run the command – docker images and it should display the imported image name in the results.
  7. Finally, Once image is created successfully, we need to create the container. It can be created using the command – docker run -d -p 80:80 [ImageName] ping -t localhost
  8. It will create the container. You can get the list of running containers using the command – docker container ls

               ——-End Of Article—–

Advertisements

TFS Release Manager–Website Application Pool Start & Stop

Requirement is to copy the updated files of the website to the target environment (Production, Staging etc.) automatically using copy task in release manager.

It can be easily implemented by using the copy task which is internally a Robocopy operation.

Issue is that the copy task will fail, if some user is already accessing the website and at the same time this task is trying to copy the files.

This problem can be handled by implementing following steps in the given order –

  1. Stop the application pool
  2. Copy the updated web files
  3. Start the application pool

Step 2 above is the available copy task in TFS RM.

Step 1 and 3 can be implemented using a PowerShell script.

Here is the content of the script –

<#

.Synopsis
Start / Stop Application Pool

.Discription
It starts or stops the application pool of a website.

.Example
powershell.exe -file .\AppPoolStopStart.ps1 ApplicationPoolName Start/Stop

. Example
powershell.exe -file .\AppPoolStopStart.ps1 DefaultAppPool Start

#>

param ([parameter(Mandatory=$True,Position=0)]
[string][ValidateNotNullOrEmpty()]$AppPoolName,

[Parameter(Mandatory=$true, Position=1)]
[string][ValidateNotNullOrEmpty()]$Action)


if ($Action -eq "stop")
{
Write-Output "Stoping the Application Pool - ($AppPoolName)......."
import-module WebAdministration
if((Get-WebAppPoolState $AppPoolName).Value -ne 'Stopped')
{
Stop-WebAppPool -Name $AppPoolName
Write-Output "Application Pool - ($AppPoolName) stopped successfully!"
}
}

if ($Action -eq "start")
{
Write-Output "Starting the Application Pool - ($AppPoolName)......."
import-module WebAdministration
if((Get-WebAppPoolState $AppPoolName).Value -ne 'Started')
{
Start-WebAppPool -Name $AppPoolName
Write-Output "Application Pool - ($AppPoolName) started successfully!"
}
}

Its can be executed as -  .\AppPoolStopStart.ps1 DefaultAppPool Start

Now add this to the source code in TFS and publish it in the build artifacts for the release definition.

In release definition, add the following tasks in the below order –

  1. Task to copy this PowerShell from the published artifacts to the target machine.
  2. Task to run PowerShell on Target Machines to execute the above PS script with an arguments as “Application Pool Name and the status as “Stop”. image
  3. Other required Release Manager tasks.
  4. Task to run PowerShell on Target Machines to execute the above PS script with an arguments as “Application Pool Name and the status as “Start”. 

           image

On successful execution of the above release definition, it will –

  1. First stop the application pool. image
  2. After successful execution of other tasks, it will finally start the application pool.image

             ——End of Article——

Windows Server 2016–Docker Container–dockerfile

Requirement is to configure docker image and run IIS based container to install/configure a website using DockerFile.

Here are the steps that needs to be done to implement the above requirement –

  1. Import microsoft/iis image from the Docker secure registry.
  2. Create the dockerfile to do the below activities –

    a. It installs .net features needed by the application.

    b. It copies application published data to the container.

    c. It creates and configures website with application pool.

    d. It sets .Net trust level.

    Note – Using this dockerfile, we can create container anywhere in any windows server 2016 environment.

    Here is the content of the dockerfile –

    ——————

FROM microsoft/iis  

SHELL ["powershell"]

RUN Install-WindowsFeature NET-Framework-45-ASPNET ; \  

    Install-WindowsFeature Web-Asp-Net45

COPY Web C:\\inetpub\\wwwroot\\Web  

RUN Remove-WebSite -Name 'Default Web Site'  

RUN New-Website -Name 'abc' -Port 80 \  

    -PhysicalPath 'C:\inetpub\wwwroot\Web' -ApplicationPool '.NET v4.5'

EXPOSE 80

RUN & c:\windows\system32\inetsrv\appcmd.exe set config /commit:WEBROOT /section:trust /level:Full

 

CMD ["ping", "-t", "localhost"]

Copy the above content into the text file and name it like dockerfile without any extension. Important note is that this file should not have any extension. Keep it in the same folder where you have kept the web folder (containing the published code of your site ‘abc’).

        3.  Built the image using the above dockerfile using the command for the location where you have kept the dockerfile – docker build –t [imageName] .

       4. Above command creates the image and you can access the list using the command – docker images

image

      5. Once image is created successfully, we need to create the container. It can be created using the command – docker run -d -p 80:80 [ImageName] ping -t localhost

It will create the container. You can get the list of running containers using the command – docker container ls

image

Complete flow of step 3,4 and 5 is given below –

image

Once all above steps are done successfully, you can browse your web application using any browser.

If you want to look inside the container, you can run the below commands and it will open the command prompt (cmd or PowerShell) inside the container and then you can using different commands to view the files –

1) For DOS command  – docker exec –I [ConatinerID] cmd

image 

2) For PowerShell command – docker exec –I [ContainerID] powershell

image

 

———-End of Article———

Docker Container–Windows 2016 Server–With SEP (Symantec Endpoint Protection)

Scenario – You have Windows Server 2016 machine and you have installed and configured Docker. After successful configuration, docker version command can give the information about the installed version.

image

You want to host IIS based website and so you have imported microsoft/iis image from docker secure registry successfully. You now wants to run the container using the command like –

docker run –d –name myFirstIISAap –p 80:80 microsoft/iis

You might get the below error message –

Error response from daemon: container c44wuweuwe323232xxxxx encountered an error during start: failure in a windows system call : This operation returned because the timeout period expired. (0x5b4)

image

Solution –

The following steps were taken:

  1. SEP V14mp1 (14.0.2332.0100) installed with all features – above issue present
  2. Remove SEP completely – no issues. Container created successfully.
  3. Re-install SEP with basic AV features only – no issues. Container created successfully.
  4. Modify SEP installation to include ADC feature – above issue present (at this stage advanced logging was enabled in SEP, error reproduced, and Symantec Diagnostic tool used to compile all logs for support purposes)
  5. Modify SEP installation to remove ADC feature and add IPS (NTP), SONAR (PTP) and Advanced Download Protection features – no issues. Container created successfully.- This could be the recommended solution.

TFS RM–Kill Process before Copy Task

Requirement

We need to copy the application executables and dlls to the XenApp environment or any other environment like Web server using TFS release manager.

Problem

Copying of executable files will fail if it is already in use as a process by some user.

Solution

To copy executable file, we need to ensure that it should not be in use. To ensure it, we need some script that detects it and if the process is running, it should kill it.

Here are the steps that can help to address the issue –

1) PowerShell script to kill the process. Here is the script that will kill the process –

<#
.Synopsis
   Script is to kill notepad* Process.
.DESCRIPTION
   Script is to kill notepad* Process.
#>

#Script Name – KillProcess.ps1
$ProcessName = "notepad*"

$ProcessInfo = get-process | Where-object {$_.ProcessName -Like $ProcessName}
if (@($ProcessInfo).Count -gt 0)
{
    Write-Output "——-Process – $ProcessName —————"
    TASKKILL /F /T /IM $ProcessName
    Write-Output "Process – $ProcessName – killed successfully!" 
    Write-Output "————————————————–" 

}

2) Add this script in TFS application repository.

3) Publish it as an artifact in the application automated build definition so that it will be available for the release automation.

4) In release automation, add below tasks

       a. Task to copy the PowerShell script to the target machine.

       b. Task for “PowerShell on Target Machines”.

      image

Output –

image

 

  ——-End of Article—–

Visual Studio 2017 – vNext Build Automation – .vdproj based installer

Problem – We need to build “.vdproj” (installer) based project in Visual Studio 2017 using vNext Build Automation.

Solution

Follow the below steps –

  1. First step is to configure the build environment.
    1. Install “Microsoft Visual Studio 2017 Installer Projects (InstallerProjects.vsix)”. Download it from https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.MicrosoftVisualStudio2017InstallerProjects.
    2. To install it, double clink on InstallerProjects.vsix and follow the default option to complete the installation.
    3. Add the below highlighted key. To add it,
      1. Add the node 15.0_[User ID]_Config like as shown below 15.0_a71083cb_Config.
      2. Add MSBuild folder (key) in it.
      3. In MSBuild, create new key “EnableOutOfProcBuild” and set its value as 0.

          image

  1. In TFS Build Definition, add task for command line and add the below information –
    1. ToolC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.com
    2. Arguments$(Build.SourcesDirectory)\Deployment.sln /build $(BuildConfiguration)
  2. Finally, initiate the build and it will build the “.vdproj” files as defined in the solution and will create MSI installer file.