How to run docker on self hosted Azure agent as non root ? (agent is locked by MS to run as root)

Viewed 1276

As you can't install Agent as a root, and docker requires root to run a commands, how is it possible to use self-hosted Azure build agents ?

I have installed the agent as non-root as per Agent requirements and installed docker as root.

User that is used to run agent cannot access the docker ;/

2 Answers

You can run the following commands in bash task.

sudo usermod -a -G docker $(whoami)
sudo chmod 0666 /var/run/docker.sock

Check the following link:

https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/docker?view=azure-devops

You can set up an Azure Pipelines self-hosted agent to run inside a Windows Server Core (for Windows hosts), or Ubuntu container (for Linux hosts) with Docker. You'll pass a few environment variables to docker run which configure the agent to connect to Azure Pipelines or Azure DevOps Server. For example:

docker run -e AZP_URL=<Azure DevOps instance> -e AZP_TOKEN=<PAT token> -e AZP_AGENT_NAME=mydockeragent dockeragent:latest
Related