AWS CodeBuild Error: Cannot Connect to Docker Daemon – How to Fix

amazon-ecsamazon-web-servicesdocker

I was trying to build docker image using aws code build service and then push it to ECR. Commands which i used for it in "buildspec.yml" is specified in below.

version: 0.2
phases:
  install:
    runtime-versions:
        docker: 18
 pre_build:
      - $(aws ecr get-login --no-include-email --region us-east-1)
      - REPOSITORY_URI=XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/devopswebbuild
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=${COMMIT_HASH:=latest}
  build:
    commands:
      - docker build -t $REPOSITORY_URI:latest .
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
  post_build:
    commands:
      - docker push $REPOSITORY_URI:latest
      - docker push $REPOSITORY_URI:$IMAGE_TAG


But i am getting error during build process, docker command is unable to connect to docker daemon.Please help me to solve these issue.

Docker build project configuration details is given below:

code

Build error details is given below:

enter image description here

Best Answer

I am answering my own question, so it may help some one who is getting same issue. Solution was pretty straightforward, i need to check the privilaged tab which i didn't notice.

enter image description here

Solution :

  1. From the AWS CodeBuild Console, select the Build Project.
  2. Select the 'Edit' dropdown from the top-right corner, and select the 'Environment' option.
  3. Within the 'Edit Environment' page, select 'Override image'. After this, scroll down to find the 'Privileged' option and select it.
  4. Select 'Update Environment' to ensure that the property is updated.
Related Topic