How to setup VSTS Private Agent to build Windows Server ver 1709 base Docker images
Do you know Windows had breaking changes for their virtualization technologies and I referred about that in Windows Container Version Compatibility | Microsoft Docs. This change will cause an error when you will build Windows Server ver 1709 base Docker images on VSTS build tasks.
Unfortunately, VSTS probably doesn't offer Hosted which are available to build Windows Server ver 1709 base Docker images. As far as I have checked, there are some "Hosted Agent" in Microsoft-hosted agents for VSTS | Microsoft Docs like below.
- Hosted VS2017 if your team uses Visual Studio 2017 - vsts-image-generation/Vs2017-Server2016-Readme.md at master · Microsoft/vsts-image-generation · GitHub
- Hosted Linux if your team uses development tools on Ubuntu.
- Hosted macOS Preview if your team uses development tools on macOS.
- Hosted if your team uses Visual Studio 2013 or Visual Studio 2015.
It was failed when I built my Windows Server ver 1709 base Docker images on VSTS build tasks, so you also need to setup your Private Agent for building Windows Server ver 1709 base Docker images. You can setup the VM following this article!
Step by Step to step Windows Server version 1709 based VM as Private Agent
You need to create new Virtual Machine on Azure Portal. Choose "Windows Server, version 1709 with Containers" for base VM, because it contains "docker.exe" command. But keep in mind the image doesn't contain "docker-compose".
You don't need to add special settings when you create VMs, but don't setup Network Security Group as completely closed to enable accessible VSTS service.
Access the VM using Remote Desktop and install Visual Studio 2017 into the VM, because the VM doesn't contain MSBuild and other commands for VSTS Build/Release processes. Follow below commands.
C:\Users\azureuser>powershell Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\Users\azureuser> curl https://aka.ms/vs/15/release/vs_community.exe -O vs_community.exe PS C:\Users\azureuser> dir Directory: C:\Users\azureuser Mode LastWriteTime Length Name ---- ------------- ------ ---- d-r--- 3/22/2018 4:19 PM 3D Objects d-r--- 3/22/2018 4:19 PM Contacts d-r--- 3/22/2018 4:19 PM Desktop d-r--- 3/22/2018 4:19 PM Documents d-r--- 3/22/2018 4:19 PM Downloads d-r--- 3/22/2018 4:19 PM Favorites d-r--- 3/22/2018 4:19 PM Links d-r--- 3/22/2018 4:19 PM Music d-r--- 3/22/2018 4:19 PM Pictures d-r--- 3/22/2018 4:19 PM Saved Games d-r--- 3/22/2018 4:19 PM Searches d-r--- 3/22/2018 4:19 PM Videos -a---- 3/22/2018 4:24 PM 1180608 vs_community.exe PS C:\Users\azureuser> .\vs_community.exe
I chose below settings in my case, but change the settings for your environment if you need.
After Visual Studio installation has completed, add MSBuild execution folder path into PATH environment variable like below.
PS C:\Users\azureuser> setx /M PATH "%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\B in" SUCCESS: Specified value was saved. PS C:\Users\azureuser>
Next, you also need to add "docker-compose" to build with it, because this base VM contains only just "docker" command. Follow below commands to install it.
PS C:\> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 PS C:\> Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.20.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\docker\docker-compose.exe PS C:\>
Finally, you need to setup VSTS Private Agent. Refer to How to setup your CentOS VMs as VSTS Private Agent - normalian blog to pick up "access token" for setup Private Agent. Note you need to setup user account of this Private Agent as "NT AUTHORITY\SYSTEM".
PS C:\agent> .\config.cmd >> Connect: Enter server URL > https://"your vsts account name".visualstudio.com Enter authentication type (press enter for PAT) > Enter personal access token > **************************************************** Connecting to server ... >> Register Agent: Enter agent pool (press enter for default) > "Your Agent Pool Name" Enter agent name (press enter for VSTSPAVM01) > Scanning for tool capabilities. Connecting to the server. Successfully added the agent Testing agent connection. Enter work folder (press enter for _work) > 2018-03-18 05:09:24Z: Settings Saved. Enter run agent as service? (Y/N) (press enter for N) > Y Enter User account to use for the service (press enter for NT AUTHORITY\NETWORK SERVICE) > NT AUTHORITY\SYSTEM Granting file permissions to 'NT AUTHORITY\SYSTEM'. Service vstsagent.daisami-online.VSTSPAVM01 successfully installed Service vstsagent.daisami-online.VSTSPAVM01 successfully set recovery option Service vstsagent.daisami-online.VSTSPAVM01 successfully configured Service vstsagent.daisami-online.VSTSPAVM01 started successfully PS C:\agent>
Now, you can choose your Private Agent in your VSTS Build/Release processes.
Note: What will be error messages if you haven't complete docker-compose
You will get "##[error]Unhandled: Failed which: Not found docker: null" message from your VSTS build task.
2018-03-17T21:07:37.4182183Z ##[section]Starting: Build an image 2018-03-17T21:07:37.4186946Z ============================================================================== 2018-03-17T21:07:37.4187316Z Task : Docker 2018-03-17T21:07:37.4187693Z Description : Build, tag, push, or run Docker images, or run a Docker command. Task can be used with Docker or Azure Container registry. 2018-03-17T21:07:37.4188244Z Version : 0.3.10 2018-03-17T21:07:37.4188534Z Author : Microsoft Corporation 2018-03-17T21:07:37.4188879Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=848006) 2018-03-17T21:07:37.4189247Z ============================================================================== 2018-03-17T21:07:37.6890544Z ##[error]Unhandled: Failed which: Not found docker: null 2018-03-17T21:07:37.6953107Z ##[section]Finishing: Build an image
Note: What will be error messages if you build Windows Server ver 1709 images with "Hosted VS2017" agent
You will get "The following Docker images are incompatible with the host operating system: [microsoft/aspnet:4.7.1-windowsservercore-1709]. Update the Dockerfile to specify a different base image." message from your VSTS build task.
2018-03-17T21:02:41.2336315Z 2018-03-17T21:02:41.2336964Z Build FAILED. 2018-03-17T21:02:41.4137038Z 2018-03-17T21:02:41.4138305Z "D:\a\1\s\Trunk\SFwithASPNetApp\SFwithASPNetApp.sln" (default target) (1) -> 2018-03-17T21:02:41.4139002Z "D:\a\1\s\Trunk\SFwithASPNetApp\docker-compose.dcproj" (default target) (3) -> 2018-03-17T21:02:41.4139575Z (DockerComposeBuild target) -> <b>2018-03-17T21:02:41.4141190Z C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.Docker.targets(111,5): error : The following Docker images are incompatible with the host operating system: [microsoft/aspnet:4.7.1-windowsservercore-1709]. Update the Dockerfile to specify a different base image. See http://aka.ms/DockerToolsTroubleshooting for more details. [D:\a\1\s\Trunk\SFwithASPNetApp\docker-compose.dcproj]</b> 2018-03-17T21:02:41.4142524Z 2018-03-17T21:02:41.4142996Z 0 Warning(s) 2018-03-17T21:02:41.4143435Z 1 Error(s) 2018-03-17T21:02:41.4143702Z 2018-03-17T21:02:41.4144142Z Time Elapsed 00:14:00.47 2018-03-17T21:02:43.2578358Z ##[error]Process 'msbuild.exe' exited with code '1'. 2018-03-17T21:02:44.0944814Z ##[section]Finishing: Build solution 2018-03-17T21:02:44.1143215Z ##[section]Starting: Post Job Cleanup 2018-03-17T21:02:44.1300074Z Cleaning any cached credential from repository: US-Crackle-Demo-Projects (Git) 2018-03-17T21:02:44.1413004Z ##[command]git remote set-url origin https://daisami-online.visualstudio.com/_git/US-Crackle-Demo-Projects 2018-03-17T21:02:44.3340613Z ##[command]git remote set-url --push origin https://daisami-online.visualstudio.com/_git/US-Crackle-Demo-Projects 2018-03-17T21:02:44.3757483Z ##[section]Finishing: Post Job Cleanup 2018-03-17T21:02:44.4763369Z ##[section]Finishing: Job
Note: What will be error messages if you setup Private Agent account as "NT AUTHORITY\NETWORK SERVICE"
Your VM can't access " //./pipe/docker_engine: " and the build tasks will be failed.
DockerGetServiceReferences: docker-compose -f "C:\agent\_work\1\s\Trunk\SFwithASPNetApp\docker-compose.yml" -f "C:\agent\_work\1\s\Trunk\SFwithASPNetApp\docker-compose.override.yml" -p dockercompose13733567670188849996 --no-ansi config C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(195,5): Error MSB4018: The "GetServiceReferences" task failed unexpectedly. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(195,5): error MSB4018: The "GetServiceReferences" task failed unexpectedly. [C:\agent\_work\1\s\Trunk\SFwithASPNetApp\docker-compose.dcproj] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(195,5): error MSB4018: Microsoft.Docker.Utilities.CommandLineClientException: error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.30/version: open //./pipe/docker_engine: Access is denied. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.. [C:\agent\_work\1\s\Trunk\SFwithASPNetApp\docker-compose.dcproj] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(195,5): error MSB4018: [C:\agent\_work\1\s\Trunk\SFwithASPNetApp\docker-compose.dcproj] C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\build\Microsoft.VisualStudio.Docker.Compose.targets(195,5): error MSB4018: For more troubleshooting information, go to http://aka.ms/DockerToolsTroubleshooting ---> Microsoft.Docker.Utilities.CommandLineClientException: error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.30/version: open //./pipe/docker_engine: Access is denied. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. [C:\agent\_work\1\s\Trunk\SFwithASPNetApp\docker-compose.dcproj]
References
- Install Docker Compose | Docker Documentation
- Use command-line parameters to install Visual Studio - Visual Studio | Microsoft Docs
Add this comment at 8/8/2018 I found an article below. Refer this if your environment doesn't work well.
stackoverflow.com