I need to run docker commands such as "docker build" and "docker push" in azure devops build pipelines. I know there are tasks available to do these things such as imagebuildingInfo@1 etc. But issue is I need to do this for a new ACR for each pipeline run, and imagebuildingInfo@1 task expects the service connection of type docker registry not azure rm. So I have to create a new service principal of every run of the pipeline which I can't do.
Is there a way to run docker commands in a script in pipeline? I am trying this
- task: AzureCLI@2
# displayName: Registry Login
# name: acrLogin
# env:
# ADME_SUBSCRIPTION: 'id'
# REGISTRY: 'acr name'
# inputs:
# azureSubscription: 'azure rm service principal'
# scriptType: 'bash'
# scriptLocation: 'inlineScript'
# inlineScript: |
# az acr login -n ${REGISTRY}
But while running this I am getting the error:
WARNING: You may want to use 'az acr login -n <acr_name> --expose-token' to get an access token, which does not require Docker to be installed.
ERROR: 2024-03-20 10:22:28.619871 An error occurred: DOCKER_COMMAND_ERROR
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Which means docker deamon is not running on the agent. We have to use a template which might be causing this not to run. Is there a way to run the docker Deamon explicitly in pipeline?





Self-hosted agentpool
If you are using a self-hosted agentpool where you install the agents yourself, and need to run the
dockercommands directly in other tasks, these are the commands on how I solved that for a self-hosted agentpool and the agent user on the VM:Installing it in this manner should solve the error:
Once installed you should be i.e. be able to do the following:
I hope this helps, good luck!