Build failed with Container docker exceeded memory limit
Asked by sureshbabu_a:

Team,

I created a CI/CD pipeline for one of our micro service but it failed with the following error.

node:14-alpine image is used to create docker image. Moreover docker build took more than 30 minutes prior failing (it's too slow)

**++Error Message++**

Container 'docker' exceeded memory limit

**++Pipeline Code++**

```
pipelines:
  branches:
    Development:
      - step:
          name: Pre-requisite step
          script:
          - echo "No pre-requisites found"
      - step:
          name: Create docker image
 ???????? script:
??????????- echo "Creating docker image"
????????? - docker build -t microservice:$BITBUCKET_BUILD_NUMBER .
????????? services:
????????? - docker
????????? caches:
????????? - docker
```

I referred the following URL

<https://community.atlassian.com/t5/Bitbucket-questions/Container-Build-exceeded-memory-limit/qaq-p/1986822>

to fix the issue but unfortunately issue is not resolved

I also tried by setting the following to increase the memory limit for docker service

```
definitions:
? ? services:
? ? ? ?docker:
? ? ? ? ? ?memory: 2048
```

and tried setting ++**size: 2x**++ in the pipeline but all failed with the same error

Kindly let me know had I missed anything

Thanks  
Sathish Kumar


Answers:
author: Oday Rafeh
body: Hi [@sureshbabu_a](/t5/user/viewprofilepage/user-id/4239122)

The error message means that the Docker container used by your pipeline has run out of memory. This can happen if your pipeline is trying to build a large image or if your pipeline is running on a machine with limited resources.

You may need to further optimize your pipeline or use a machine with more resources.

Please try:

* Split the Docker build process into smaller steps or use multi-stage builds to reduce the memory footprint of the build process.
* Optimize your Dockerfile to reduce the size of the final image. You can use techniques such as removing unnecessary packages or compressing files to reduce the size of the image.
* Use a machine with more memory or CPU resources to run your pipeline. You can try increasing the size of the machine or using a different machine type with more resources.
* Consider using a container registry to store your Docker images instead of building them on the fly. This can reduce the build time and memory requirements of your pipeline.

comments: author: sureshbabu_a
body: Hi [@Oday Rafeh](/t5/user/viewprofilepage/user-id/5172837)

Thank you for replying to my question.

As suggested. I would try to convert it to multi-stage docker image. However, I've got another question.

"Use a machine with more memory or CPU resources to run your pipeline. You can try increasing the size of the machine or using a different machine type with more resources."

How to select / use a different machine on BitBucket Cloud ? Kindly let us know if it possible to use a different machine as we are a subscribed user.

Regards  
Sathish Kumar


author: Oday Rafeh
body: Hi [@sureshbabu_a](/t5/user/viewprofilepage/user-id/4239122) ,

To use a different machine for your Bitbucket Cloud pipeline, you can use the "size" parameter in your pipeline configuration. This parameter allows you to specify the size of the machine that your pipeline runs on.

For example, you can use "size: 2x" to specify that your pipeline should run on a machine with double the resources of the default machine.

Here's an example pipeline configuration that sets the machine size to 2x:

```
pipelines:
default:
- step:
name: Build and test
size: 2x
script:
- echo "Building and testing..."

```

Note that not all sizes may be available in all regions, and larger sizes may come with additional costs. You can check the Bitbucket Cloud pricing page for more information.

I hope this helps! Let me know if you have any further questions.

Best regards,  
Oday Rafeh


Tags: bitbucket-cloud

cloud