I want to setup a Docker container to support builds of the code base which is entirely written in C++, and the generated application runs on Windows only.
For this purpose, I need to setup a container replicating our current build environment to support the builds.
I need to create a Dockerfile something like below to build such a container:
Please consider the following as kind of pseudo-code Dockerfile(ignore the apt-get and consider any other utility in windows to install tools from command line):
FROM: Windows10 // A base windows kernel
RUN apt-get install -y VisualStudio // Installing the Visual Studio for compilation of C++ files
RUN apt-get install -y cygwin // Since I am using some cygwin utlities in build process
RUN apt-get install -y SigningTool // A tool I need to sign the exe
RUN apt-get install -y CompressionTool // A tool I need to compress the exe
RUN apt-get install -y BuildSystem // Custom in-house build system to generate the builds of the source code
CMD ['BuildSystem debug']
Note: We have a custom build system ( and not using GNU Make) in our organization to perform the builds. debug is the target provided to the build system, since I want to build a debug executable.
My doubts are:
How do I install a VisualStudio compiler ( or any other compiler that runs on windows)
How do I host the SigningTool , CompressionTool and other executables (on Docker Trusted Registry; whether is it possible to host the executables on DTR)
How do I take care of the licensing of the above tools (compiler, signingtool, compressiontool all require licenses to run).
The above works absolutely fine in our organization. But the process of setting up a machine (installation and all of the above tools takes a lot of time and effort). Hence, I want to create a Docker image that can be deployed on a bare machine, which will have the whole build environment setup and running in very less time.
A more important purpose of doing so is to adopt the Continuous Delivery methodology.
Please provide your inputs on the same(try to consider all the doubts).
You can install Visual Studio Build Tools into a Windows container to support continuous integration and continuous delivery (CI/CD) workflows. This article guides you through what Docker configuration changes are required as well as what workloads and components you can install in a container.
You can run any application in Docker as long as it can be installed and executed unattended, and the base operating system supports the app. Windows Server Core runs in Docker which means you can run pretty much any server or console application in Docker.
Microsoft is using Docker's services to underpin its Windows Server containers. You can build and test code running inside them on Windows PCs, running either Pro or Enterprise builds, and the upcoming 2004 release of Windows 10 brings WSL2 and support for Linux containers running on Windows.
You can run both Linux and Windows programs and executables in Docker containers. The Docker platform runs natively on Linux (on x86-64, ARM and many other CPU architectures) and on Windows (x86-64). Docker Inc. builds products that let you build and run containers on Linux, Windows and macOS.
I assume you can already run Windows containers, ex. docker run -it microsoft/windowsservercore
Here is my Dockerfile to install Visual C++ Build Tools 2015 in Docker container using Chocolatey:
# escape=`
FROM microsoft/windowsservercore
# Install chocolatey
RUN @powershell -NoProfile -ExecutionPolicy unrestricted -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1"
# Install Visual C++ Build Tools, as per: https://chocolatey.org/packages/visualcpp-build-tools
RUN choco install visualcpp-build-tools -version 14.0.25420.1 -y
# Add msbuild to PATH
RUN setx /M PATH "%PATH%;C:\Program Files (x86)\MSBuild\14.0\bin"
# Test msbuild can be accessed without path
RUN msbuild -version
CMD [ "cmd.exe" ]
Using Choco is simpler, but you can get the same result with downloading native web installer and running it in quiet mode, for example:
visualcppbuildtools_full.exe /Q /L <LogFile> /Full
In answer to your first point only: there is a document here that I used as a starting point for a Docker image to compile a Windows C++ application: Install Build Tools into a Container
I am running Docker on Windows Server 2016 and compiling a legacy application that targets XP.
My eventual Dockerfile
looked like this:
# Use the latest Windows Server Core image.
FROM microsoft/windowsservercore
# Download the Visual Studio 2017 installer outside of the PATH.
# This is required for Windows SDK 7.1A (XP targetting)
ADD https://aka.ms/vs/15/release/vs_professional.exe C:\\TEMP\\vs_professional.exe
# Add C:\Bin to PATH and install Build Tools with components we need
RUN setx /m PATH "%PATH%;C:\Bin" \
&& C:\TEMP\vs_professional.exe --quiet --wait --norestart --nocache \
--add Microsoft.VisualStudio.Component.Static.Analysis.Tools \
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 \
--add Microsoft.VisualStudio.Component.VC.CMake.Project \
--add Microsoft.VisualStudio.Component.VC.CoreBuildTools \
--add Microsoft.VisualStudio.Component.VC.ATLMFC \
--add Microsoft.VisualStudio.Component.VC.ATL \
--add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop \
--add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP \
--add Microsoft.VisualStudio.Component.Windows10SDK.16299.UWP.Native \
--add Microsoft.VisualStudio.Component.Windows10SDK \
--add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81 \
--add Microsoft.VisualStudio.Component.VC.Redist.14.Latest \
--add Microsoft.Component.VC.Runtime.UCRTSDK \
--add Microsoft.VisualStudio.Component.WinXP \
|| IF "%ERRORLEVEL%"=="3010" EXIT 0
# Start developer command prompt with any other commands specified.
ENTRYPOINT "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" &&
# Default to PowerShell if no other command specified.
CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"]
Just to be clear, you would need docker for Windows for this.
And I am not talking about Docker for Mac and Windows Beta, which would run a Linux (Alpine) host on a Hyper-V VM on Windows: that would not run any Windows image, only Linux images.
I am talking about Docker for Windows (provided your Windows10 has the latest Hyper-V feature). Up to very recently, that was only possible on a Windows Server 2016 TP4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With