最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Docker Image Builder in ADO pipeline - Stack Overflow

programmeradmin1浏览0评论

I am Trying to build the container image through ADO pipeline and docker Task , While running Bash@3 Task getting Bash Error , that I added below. and if I skip the Bash@3 task getting another error with docker@3 task that I added below . Could some one help to fix this and agent is running on AKS pods based agent.

    - task: DockerInstaller@0
      inputs:
        dockerVersion: '27.2.1'
     - task: Bash@3
       displayName: 'sudo status check'
       inputs:
         targetType: 'inline'
         script: |   
           docker --version
           sudo systemctl restart docker     
    - task: Docker@2
      displayName: Build and publish image to Azure Container Registry
      inputs:
        command: 'buildAndPush'
        containerRegistry: $(dockerRegistryServiceConnection)
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        tags: |
          $(tag)
          latest

Bash Error

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required

Docker@3 error

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
/azp/_work/_tool/docker-stable/27.2.1/x64/docker pull ubuntu:22.04
/azp/_work/_tool/docker-stable/27.2.1/x64/docker inspect ubuntu:22.04
[]

DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            /

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

##[error]DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
##[error]            Install the buildx component to build images with BuildKit:
##[error]            /
##[error]Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
##[error]The process '/azp/_work/_tool/docker-stable/27.2.1/x64/docker' failed with exit code 1

I am Trying to build the container image through ADO pipeline and docker Task , While running Bash@3 Task getting Bash Error , that I added below. and if I skip the Bash@3 task getting another error with docker@3 task that I added below . Could some one help to fix this and agent is running on AKS pods based agent.

    - task: DockerInstaller@0
      inputs:
        dockerVersion: '27.2.1'
     - task: Bash@3
       displayName: 'sudo status check'
       inputs:
         targetType: 'inline'
         script: |   
           docker --version
           sudo systemctl restart docker     
    - task: Docker@2
      displayName: Build and publish image to Azure Container Registry
      inputs:
        command: 'buildAndPush'
        containerRegistry: $(dockerRegistryServiceConnection)
        repository: $(imageRepository)
        dockerfile: $(dockerfilePath)
        tags: |
          $(tag)
          latest

Bash Error

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required

Docker@3 error

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
/azp/_work/_tool/docker-stable/27.2.1/x64/docker pull ubuntu:22.04
/azp/_work/_tool/docker-stable/27.2.1/x64/docker inspect ubuntu:22.04
[]

DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker/go/buildx/

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

##[error]DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
##[error]            Install the buildx component to build images with BuildKit:
##[error]            https://docs.docker/go/buildx/
##[error]Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
##[error]The process '/azp/_work/_tool/docker-stable/27.2.1/x64/docker' failed with exit code 1
Share Improve this question edited Mar 19 at 12:35 bryanbcook 18.8k2 gold badges47 silver badges79 bronze badges asked Mar 19 at 0:14 pkspks 517 bronze badges 3
  • Your pod based agent seems need docker daemon pre-installed if using Docker@2, and for bash@3 have you tried to remove sudo ? – wenbo - Finding Job Commented Mar 19 at 2:15
  • Hi @pks, Have you got a chance to check my answer to use a container agent that bind-mounts the Docker socket in order to use Docker in Docker container? Hope the information may help resolve the issue in your post. Thx. – Alvin Zhao - MSFT Commented Mar 20 at 1:12
  • yes @AlvinZhao-MSFT thanks – pks Commented Mar 24 at 20:26
Add a comment  | 

1 Answer 1

Reset to default 1

I could reproduce the issue when the pipeline was running on a container agent.

Please note that,

In order to use Docker from within a Docker container, you bind-mount the Docker socket.

Doing this has serious security implications. The code inside the container can now run as root on your Docker host.

Docker was replaced with containerd in Kubernetes 1.19, and Docker-in-Docker became unavailable.

If you're sure you want to proceed with this approach, you can start the container agent using the following command that bind-mounts the Docker socket, as you can see in my second attempt, the pipeline run was succeeded.

docker run -d \
  -e AZP_URL="https://dev.azure/xxxYourADOOrgNamexxx/" \
  -e AZP_TOKEN="$PAT" \
  -e AZP_POOL="xxxDockerPool" \
  -e AZP_AGENT_NAME="xxx-DockerAgent" \
  --name "azp-agent-linux" \
  -v /var/run/docker.sock:/var/run/docker.sock \
  azp-agent:linux

Before proceeding, consider whether it is necessary to build a Docker image on a container agent. There are other safer and more scalable options, such as, Microsoft-hosted, self-hosted, VMSS and MDP agents.

发布评论

评论列表(0)

  1. 暂无评论