14
votes

I'm trying to get a simple docker app to build using AWS codebuild, but I am coming across an error where the aws command is not found:

[Container] 2016/12/10 04:29:17 Build started on Sat Dec 10 04:29:17 UTC 2016
[Container] 2016/12/10 04:29:17 Running command echo Building the Docker image...
[Container] 2016/12/10 04:29:17 Building the Docker image...
[Container] 2016/12/10 04:29:17 Running command docker build -t aws-test .
[Container] 2016/12/10 04:29:17 sh: 1: docker: not found
[Container] 2016/12/10 04:29:17 Command did not exit successfully docker build -t aws-test . exit status 127
[Container] 2016/12/10 04:29:17 Phase complete: BUILD Success: false
[Container] 2016/12/10 04:29:17 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t aws-test .. Reason: exit status 127

I've got a super simple docker file which builds a simple express app:

FROM node:6.2.0

# Create app directory
RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

# Install app dependencies
COPY package.json /usr/src/app/

# Bundle app source
COPY . /usr/src/app

EXPOSE 3000

CMD npm install && npm start

And I've got a super simple buildspec.yml which is suppose to build the docker container and push it to the aws registry:

version: 0.1

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - $(aws ecr get-login --region us-west-2)
  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...          
      - docker build -t <CONTAINER_NAME> .
      - docker tag <CONTAINER_NAME>:latest <ID>.dkr.ecr.us-west-2.amazonaws.com/<CONTAINER_NAME>:latest
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push <ID>.dkr.ecr.us-west-2.amazonaws.com/<CONTAINER_NAME>:latest

However once ran, it throws the error posted above ^^ I'm not sure why the aws cli utils aren't found? This guide here:

http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html

Suggests I don't need to do anything to setup the aws cli utils anywhere?

Also one other thing I noticed, I removed $(aws ecr get-login --region us-west-2) step from the buildspec file, built it again and it then said that the docker command was not found?! Have I missed a step somewhere (I don't think I have).

1
What is the image you're using as the project environment? Are you using one of the CodeBuild managed environments?Clare Liguori
Thank you very much @ClareLiguori I was a bit confused and used the wrong env container. You can create an answer and I'll accept it if you like?James111

1 Answers

17
votes

So it turned out I was using the wrong environment. Here is what I'm using now:

Now

I was trying to specify my own docker image, which was ultimately not setup with any of the AWS cli utils!

Thanks to @Clare Liguori for tipping me off!