AWS CodeBuild - GitHub Actions: COMMAND_EXECUTION_ERROR Message: Error while executing command | [error]Docker pull failed with exit code 1

· 2 min read
AWS CodeBuild - GitHub Actions:  COMMAND_EXECUTION_ERROR Message: Error while executing command | [error]Docker pull failed with exit code 1

For GitHub Docker container actions, "build project must have privileged mode enabled and be run by the default Docker user (root)."  Otherwise, build will fail with following error logs.

[Container] 2023/07/11 02:09:11 Entering phase PRE_BUILD
[Container] 2023/07/11 02:09:11 Preparing action command
[Container] 2023/07/11 02:09:13 Current runner version: '2.304.0'
[Container] 2023/07/11 02:09:13 Preparing the runtime environment
[Container] 2023/07/11 02:09:16 /usr/local/bin/docker pull ghcr.io/github/super-linter:v4.10.0
[Container] 2023/07/11 02:09:17 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[Container] 2023/07/11 02:09:17 ##[warning]Docker pull failed with exit code 1, back off 7.952 seconds before retry.
[Container] 2023/07/11 02:09:25 /usr/local/bin/docker pull ghcr.io/github/super-linter:v4.10.0
[Container] 2023/07/11 02:09:25 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[Container] 2023/07/11 02:09:25 ##[warning]Docker pull failed with exit code 1, back off 6.009 seconds before retry.
[Container] 2023/07/11 02:09:31 /usr/local/bin/docker pull ghcr.io/github/super-linter:v4.10.0
[Container] 2023/07/11 02:09:31 Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
[Container] 2023/07/11 02:09:31 ##[error]Docker pull failed with exit code 1

[Container] 2023/07/11 02:09:31 Command failed with exit status 2
[Container] 2023/07/11 02:09:31 Phase complete: PRE_BUILD State: FAILED
[Container] 2023/07/11 02:09:31 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: - name: Lint Code Base
  uses: github/super-linter@v4
  env:
    DEFAULT_BRANCH: main
    VALIDATE_ALL_CODEBASE: "true"
. Reason: exit status 2

buildspec.yml used for this demo

version: 0.2
phases:
  pre_build:
    steps:
      - name: Lint Code Base
        uses: github/super-linter@v4
        env:
          VALIDATE_ALL_CODEBASE: 'true'
          DEFAULT_BRANCH: main

Shorts:

Fix:

For existing AWS CodeBuild projects, select the project and edit the environment.

Edit AWS CodeBuild Environment

Click 'Override image".

Override current environment image

Select the "Privileged" checkbox ("Enable this flag if you want to build Docker images or want your builds to get elevated privileges.") and click "Update environment".

This will fix the Docker daemon access related issue.

For new project, you get the same option to enable it while selecting the environment image.

create-aws-codebuild-environment

References