Self-hosted TFS Linux Build agent for Docker – The type initializer for ‘’ threw an exception

In the previous post that I demonstrated how to create a Self-hosted Build Agent on Windows. As I implemented Docker integration to the CI/CD DevOp pipeline on TFS, I need to make sure my build agent can build and push Docker image to Registry. The simple option is to installing Docker to our VM Windows Server, however, there are lots of issues to run Docker Windows on top of VM. I decided to create Linux VM for build agent and install Docker into it.

Following the same instructions to create build agent on Windows. The only issue is to run the on Linux, it throws an System.Net.Http.CurlHandler due to missing OpenSSL. The following approach can work for both Linux or MacOS.

brew update
brew install openssl
mkdir -p /usr/local/lib
sudo ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
sudo ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

then install the agent again

~/myagent$ ./

To run Agent as a Service:

sudo su
./ install
./ run

Then you just need to install Docker on Linux by using following commands.

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] xenial stable"
sudo apt-get update

apt-cache search docker-ce

sudo apt-get install docker-ce

Test if Docker is running with the following command

docker run hello-world

Permission issue when running docker with the build agent

Assign $USER to docker group
sudo usermod -a -G docker $USER
systemctl start docker
gpasswd -a $USER docker

** To build .NET Core application with Linux build, you need to install Java (for getting the source code) and .NET Core Sdk
wget -q
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get install dotnet-sdk-2.1

Install Java

sudo add-apt-repository ppa:webupd8team/java
sudo apt update; sudo apt install oracle-java8-installer

Posted by justinpham

Leave a Reply