# My image builds are slow, how can I make them faster?

**URL:** <https://community.okteto.com/t/my-image-builds-are-slow-how-can-i-make-them-faster/1061>\
**Category:** How Do I?\
**Tags:** dockerfile, performance, helm\
**Created:** [September 28, 2023, 6:36am UTC](https://community.okteto.com/t/my-image-builds-are-slow-how-can-i-make-them-faster/1061 "2023-09-28T06:36:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pchico83](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/pchico83/32/25_2.png) [@pchico83](https://community.okteto.com/u/pchico83)\
**Post date:** [September 28, 2023, 6:36am UTC](https://community.okteto.com/t/my-image-builds-are-slow-how-can-i-make-them-faster/1061/1 "2023-09-28T06:36:31Z")

</div>

When building my images in Okteto, image builds are slower than in my laptop

---

<div class="post-metadata">

**Author:** ![pchico83](https://sea1.discourse-cdn.com/flex019/user_avatar/community.okteto.com/pchico83/32/25_2.png) [@pchico83](https://community.okteto.com/u/pchico83)\
**Post date:** [November 13, 2023, 3:52pm UTC](https://community.okteto.com/t/my-image-builds-are-slow-how-can-i-make-them-faster/1061/2 "2023-11-13T15:52:10Z")

</div>

Fast image builds are a crucial part of the Okteto developer experience. These builds are executed within the [Okteto Build service](https://www.okteto.com/docs/cloud/build/), designed for high performance by minimizing redundant image builds and maximizing the utilization of image cache and layers.

To enhance the speed of your image builds, we recommend adhering to several best practices:

- Follow Dockerfile best practices
- Configure CPU/Memory resources for the Okteto Build service
- Configure faster storage for the Okteto Build service

## Follow Dockerfile best practices

Dockerfiles offer various optimizations to facilitate cache reuse during builds. From a performance perspective, consider the following recommendations:

- Utilize a **`.dockerignore`** file to exclude files that are irrelevant to the image build process. This minimizes the time required to transfer your local files to the Okteto Build service. For detailed guidance, consult the official [.dockerignore file](https://docs.docker.com/engine/reference/builder/#dockerignore-file) documentation.
- Arrange Dockerfile instructions from those that change infrequently to those that change more frequently. This sequence aids in leveraging the Dockerfile build cache. Below is an example of the recommended order of instructions:
  - Install tools you need to build your application
  - Install or update library dependencies
  - Generate your application

- Use [buildkit cache mounts](https://docs.docker.com/build/guide/mounts/) to persist cache folders between image builds. Leverage [buildkit cache mounts](https://docs.docker.com/build/guide/mounts/). We have a tutorial explaining [how to use cache mounts for webpack/nodejs](https://www.okteto.com/blog/building-docker-images-faster-for-webpack/). Follow [this link](https://github.com/actions/cache#implementation-examples) for a list of the cache folder used by the main programming language and frameworks.

## Configure CPU/Memory resources for the Okteto Build service

Okteto Self-Hosted users can configure the CPU and memory resources allocated for the Okteto Build service by modifying the [buildkit section](https://www.okteto.com/docs/self-hosted/administration/configuration/#buildkit) in your Okteto helm values file. For instance, the following configuration reserves 1 CPU and 4 GB of memory for the Okteto Build service, with a limit of 2 CPUs and 8GB of memory:

```yaml
buildkit:
  resources:
    requests:
      cpu: 1
      memory: 4GB
    limits:
      cpu: 2
      memory: 8GB          

```

Note that the performance of the Okteto Build service can be significantly influenced by the type of processor it runs on. Different virtual machines (VMs) may have processors with varying capabilities. You can enhance performance by configuring the Okteto Build service to run on a dedicated node pool with a high-speed processor using the Okteto helm values section [tolerations.buildPool](https://www.okteto.com/docs/self-hosted/administration/configuration/#tolerations):

```yaml
tolerations:
  buildPool: build

```

Moreover, to further optimize performance, you can scale the Okteto Build service instances based on CPU utilization by either configuring more instances with `buildkit.replicaCount` or utilizing `buildkit.hpa` to implement a Horizontal Pod Autoscaler based on CPU utilization:

```yaml
buildkit:
  replicaCount: 2
  hpa:
    enabled: true
    min: 2
    max: 4
    CPU: 50

```

## Configure faster storage for the Okteto Build service

Okteto Self-Hosted users can configure the storage class associated with the Okteto Build service. Image builds are inherently I/O intensive, and opting for SSDs over standard disks can substantially impact build performance. You can configure the storage class of Okteto Build service by setting the `buildkit.persistence.storageClass` field. The fields `buildkit.persistence.size` and `buildkit.persistence.cache` configure the size of the Okteto Build service storage and cache folders:

```yaml
buildkit:
  persistence:
    enabled: true
    storageClass: ssd
    size: 800Gi
    cache: 600000

```
