Search code examples
dockercontainerspipelineaws-codebuild

Running docker inside a container in AWS CodeBuild


I got a Java application. In local, I can connect to Dev Container using Visual Studio Code. Now I wanna build a CodePipeline in AWS. But it displays an error like this when I tried to start docker in CodeBuild's Ubuntu standard 7.0 container:

[Container] 2023/05/20 12:13:06 Running command sudo service docker start /etc/init.d/docker: 96: ulimit: error setting limit (Operation not permitted)

Please help. Here's my buildspec.yml:

phases:
  install:
    commands:
      - cat /etc/os-release
      - sudo apt update -y
      - sudo apt install -y apt-transport-https ca-certificates curl gnupg lsb-release
      - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
      - echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
      - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
      - sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose
      - sudo service docker start
  build:
    commands:
      - docker-compose up -d

My build image: enter image description here


Solution

  • Just tick that highlighted privileged checkbox, and save the latest configurations.

    You can see, it is already mentioned there that you need to enable this flag in order to build docker images inside the CodeBuild agent.

    enter image description here