17

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:

  1. How do I install a VisualStudio compiler ( or any other compiler that runs on windows)

  2. How do I host the SigningTool , CompressionTool and other executables (on Docker Trusted Registry; whether is it possible to host the executables on DTR)

  3. 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).

3 Answers 3

9

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
6

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"]
1
  • This is super cool! Is there any update for visual c++ 2019? May 21, 2021 at 10:10
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.