aws-codebuild-docker-images icon indicating copy to clipboard operation
aws-codebuild-docker-images copied to clipboard

Couldn't connect to Docker daemon at http+docker://localhost - is it running?

Open deleugpn opened this issue 7 years ago • 5 comments

I'm trying to migrate from aws/codebuild/docker:18.09.0 to Image: aws/codebuild/standard:2.0 and I'm getting the error that the Docker daemon is not running. Here's my CodeBuild setup:

Description: 'Integrate Code Build with GitHub Pull Requests'
Resources:
  CodeBuildProject:
    Type: AWS::CodeBuild::Project
    Properties:
      ServiceRole: !ImportValue GeneralPurposeCodeBuildRoleArn
      Artifacts:
        Type: no_artifacts
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_LARGE
        Image: aws/codebuild/standard:2.0
        PrivilegedMode: true
      Source:
        Auth:
          Type: OAUTH
        Location: https://github.com/my/repo
        Type: GITHUB
        BuildSpec: amazon/builds/buildspec.yaml
      Triggers:
        Webhook: true
      TimeoutInMinutes: 10

Here's the buildspec

version: 0.2

phases:
  install:
    runtime-versions:
      docker: 18

  pre_build:
    commands:
      - $(aws ecr get-login --region $AWS_REGION --no-include-email)
      - REGISTRY_URL="xxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com/"
  build:
    commands:
      - chmod 777 test.sh
      - sh test.sh

Here's test.sh

#!/usr/bin/env sh

docker run --entrypoint develop.sh -v $(pwd):/var/task -it deleugpn/bref:build-7.3.2

docker-compose up -d

docker-compose exec service-a sh -c "chmod 755 ./tests/setup/init.sh; sh tests/setup/init.sh"

docker-compose exec service-b sh -c "chmod 755 ./tests/setup/init.sh; sh tests/setup/init.sh"

docker-compose exec -w /var/task service-c /var/task/vendor/bin/phpunit --testdox

And finally here's the full CodeBuild output

[Container] 2019/06/03 08:48:37 Waiting for agent ping 
[Container] 2019/06/03 08:48:39 Waiting for DOWNLOAD_SOURCE 
[Container] 2019/06/03 08:48:41 Phase is DOWNLOAD_SOURCE 
[Container] 2019/06/03 08:48:41 CODEBUILD_SRC_DIR=/codebuild/output/src345830443/src/github.com/cgauge/4.0-database-listener 
[Container] 2019/06/03 08:48:41 YAML location is /codebuild/output/src345830443/src/github.com/cgauge/4.0-database-listener/amazon/builds/buildspec.yaml 
[Container] 2019/06/03 08:48:41 No commands found for phase name: INSTALL 
[Container] 2019/06/03 08:48:41 Processing environment variables 
[Container] 2019/06/03 08:48:41 Moving to directory /codebuild/output/src345830443/src/github.com/cgauge/4.0-database-listener 
[Container] 2019/06/03 08:48:41 Registering with agent 
[Container] 2019/06/03 08:48:41 Phases found in YAML: 3 
[Container] 2019/06/03 08:48:41  PRE_BUILD: 2 commands 
[Container] 2019/06/03 08:48:41  BUILD: 2 commands 
[Container] 2019/06/03 08:48:41  INSTALL: 0 commands 
[Container] 2019/06/03 08:48:41 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED 
[Container] 2019/06/03 08:48:41 Phase context status code:  Message:  
[Container] 2019/06/03 08:48:41 Entering phase INSTALL 
[Container] 2019/06/03 08:48:41 Running command echo "Installing Docker version 18 ..." 
Installing Docker version 18 ... 
 
[Container] 2019/06/03 08:48:41 Phase complete: INSTALL State: SUCCEEDED 
[Container] 2019/06/03 08:48:41 Phase context status code:  Message:  
[Container] 2019/06/03 08:48:41 Entering phase PRE_BUILD 
[Container] 2019/06/03 08:48:41 Running command $(aws ecr get-login --region $AWS_REGION --no-include-email) 
WARNING! Using --password via the CLI is insecure. Use --password-stdin. 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json. 
Configure a credential helper to remove this warning. See 
https://docs.docker.com/engine/reference/commandline/login/#credentials-store 
 
Login Succeeded 
 
[Container] 2019/06/03 08:48:46 Running command REGISTRY_URL="xxxxxxxxxx.dkr.ecr.eu-west-1.amazonaws.com/" 
 
[Container] 2019/06/03 08:48:46 Phase complete: PRE_BUILD State: SUCCEEDED 
[Container] 2019/06/03 08:48:46 Phase context status code:  Message:  
[Container] 2019/06/03 08:48:47 Entering phase BUILD 
[Container] 2019/06/03 08:48:47 Running command chmod 777 test.sh 
 
[Container] 2019/06/03 08:48:47 Running command sh test.sh 
the input device is not a TTY 
Couldn't connect to Docker daemon at http+docker://localhost - is it running? 
 
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. 
Couldn't connect to Docker daemon at http+docker://localhost - is it running? 
 
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. 
Couldn't connect to Docker daemon at http+docker://localhost - is it running? 
 
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. 
Couldn't connect to Docker daemon at http+docker://localhost - is it running? 
 
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable. 
 
[Container] 2019/06/03 08:48:49 Command did not exit successfully sh test.sh exit status 1 
[Container] 2019/06/03 08:48:49 Phase complete: BUILD State: FAILED 
[Container] 2019/06/03 08:48:49 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: sh test.sh. Reason: exit status 1 
[Container] 2019/06/03 08:48:49 Entering phase POST_BUILD 
[Container] 2019/06/03 08:48:49 Phase complete: POST_BUILD State: SUCCEEDED 
[Container] 2019/06/03 08:48:49 Phase context status code:  Message:  

I'm sorry to say that this deprecation of the previous image has been an awful customer experience from AWS. It seems like it is lacking a lot of documentation for such a big change without going through a proper migration plan from the previous images to the new ones.

deleugpn avatar Jun 03 '19 08:06 deleugpn

After speaking with the AWS CodeBuild team, I tried to setup a minimum reproducible project and it worked fine. I then proceeded to delete my CodeBuild project and recreated from scratch and it fixed the issue. Perhaps this was caused by the fact that I created the CodeBuild project without Privilege Mode and then edited it to add Privilege Mode.

deleugpn avatar Jun 04 '19 13:06 deleugpn

Got this same error and setting privileged mode to true fixed the problem.

blueshirts avatar Jun 27 '19 22:06 blueshirts

https://docs.aws.amazon.com/codebuild/latest/userguide/create-project.html#create-project-cli

You must specify privilegedMode with a value of true only if you plan to use this build project to build Docker images, and the build environment image you specified is not provided by CodeBuild with Docker support. Otherwise, all associated builds that attempt to interact with the Docker daemon fail. You must also start the Docker daemon so that your builds can interact with it. One way to do this is to initialize the Docker daemon in the install phase of your build spec by running the following build commands. Do not run these commands if you specified a build environment image provided by CodeBuild with Docker support.

- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay&
- timeout -t 15 sh -c "until docker info; do echo .; sleep 1; done"

gene1wood avatar Jul 17 '19 22:07 gene1wood

Thanks @gene1wood. I actually needed to remove the -t from timeout (at least some versions of timeout don't use it - http://man7.org/linux/man-pages/man1/timeout.1.html)

- timeout15 sh -c "until docker info; do echo .; sleep 1; done"

playerfm avatar Dec 04 '19 15:12 playerfm

Same thing here, recreating the project with Privilege Mode fixed the issue

milkolori avatar Apr 07 '22 16:04 milkolori