You have installed azure build agent on host machine and jobs are running fine. Now you want to control the context where the job is run then container jobs are best suited to have that control. As container jobs will run in containers providing isolation from host, it allows you to control and use specific versions of tools and dependencies. This way it requires less initial setup on host where agent runs and less infrastructure to maintain.
Note: The container jobs will not work if build agent itself is running in container.
In this article you will see how to build and test a simple application written in GoLang.
Download hello-world.go app code.
The repo includes azure-pipelines.yml
The build pipeline runs within golang container. The container job is run on Microsoft hosted build agent (Ubuntu). Drawback of using MS hosted build agent is that it will download the golang image every time before running it as a container. If this is run on self hosted build agent then it will download the image once only.