Bitbucket Pipelines provides a feature that enables you to configure memory in Docker services (learn more on that here).

We have related highly voted suggestion where customers would like to configure multiple Docker services, each with different memory configurations.

Here’s a working example of how you can set memory limits to multiple Docker services and use the appropriate service depending on the step requirements.

definitions:
  services:
    docker:
      memory: 512
    docker-with-more-memory:
      memory: 2048
      type: docker
    docker-with-large-memory:
      memory: 5120
      type: docker

pipelines: 
  custom:
    pipeline1:
      - step:
         services: [docker]
         script:
           - echo "Docker service with 512 MB memory"
    pipeline2:
      - step:
         services: [docker-with-more-memory]
         script:
           - echo "Docker service with 2048 MB memory"
    pipeline3:
      - step:
         services: [docker-with-large-memory]
         size: 2x
         script:
           - echo "Docker service with 5120 MB memory"

Configuring multiple Docker services with different memory limits