Execute docker command in Docker container Azure DevOps Pipeline agent

100 Views Asked by At

I have created a Self Hosted Docker container agent in Azure DevOps.

Now, in Azure DevOps. I have created a pipeline and I am using the Self Hosted COntainer Agent to execute the docker run command. On trying that I am getting an error stating docker daemon is not running.

Post that I tried to execute sudo systemctl enable docker; sudo systemctl start docker; etc. but unfortunately, this did not work as I was asked for a password.

Please let me know if more clarity is needed.

1

There are 1 best solutions below

0
wade zhou - MSFT On

Running Docker commands inside a container to manage other containers is known as Docker Inside Docker (DinD), both containers should use host's daemon which is mentioned in official link.

To achieve this, you can mount the Docker socket (usually located at /var/run/docker.sock) into your container. This allows the container to communicate with the Docker daemon on the host.

To start the agent:

docker run -v /var/run/docker.sock:/var/run/docker.sock \
-e AZP_URL=<YOUR-ORGANIZATION-URL> \
-e AZP_TOKEN=<YOUR-TOKEN> \
-e AZP_AGENT_NAME='Ubuntu Docker' devopsubuntu-docker:latest

You can check the links below for more details:

Self-hosted Azure DevOps agents running in Docker

Running Docker commands inside Docker containers (on Windows)