Home Explore Blog CI



docker

1st chunk of `content/manuals/build-cloud/optimization.md`
d96373cefbd9ee3532e77fb02a0855775f88e9731c1f77fc000000010000087d
---
title: Optimize for building in the cloud
linkTitle: Optimization
weight: 40
description: Building remotely is different from building locally. Here's how to optimize for remote builders.
keywords: build, cloud build, optimize, remote, local, cloud
aliases:
  - /build/cloud/optimization/
---

Docker Build Cloud runs your builds remotely, and not on the machine where you
invoke the build. This means that file transfers between the client and builder
happen over the network.

Transferring files over the network has a higher latency and lower bandwidth
than local transfers. Docker Build Cloud has several features to mitigate this:

- It uses attached storage volumes for build cache, which makes reading and
  writing cache very fast.
- Loading build results back to the client only pulls the layers that were
  changed compared to previous builds.

Despite these optimizations, building remotely can still yield slow context
transfers and image loads, for large projects or if the network connection is
slow. Here are some ways that you can optimize your builds to make the transfer
more efficient:

- [Dockerignore files](#dockerignore-files)
- [Slim base images](#slim-base-images)
- [Multi-stage builds](#multi-stage-builds)
- [Fetch remote files in build](#fetch-remote-files-in-build)
- [Multi-threaded tools](#multi-threaded-tools)

For more information on how to optimize your builds, see
[Building best practices](/manuals/build/building/best-practices.md).

### Dockerignore files

Using a [`.dockerignore` file](/manuals/build/concepts/context.md#dockerignore-files),
you can be explicit about which local files you don’t want to include in the
build context. Files caught by the glob patterns you specify in your
ignore-file aren't transferred to the remote builder.

Some examples of things you might want to add to your `.dockerignore` file are:

- `.git` — skip sending the version control history in the build context. Note
  that this means you won’t be able to run Git commands in your build steps,
  such as `git rev-parse`.
- Directories containing build artifacts, such as binaries. Build artifacts
  created locally during development.

Title: Optimizing Builds for Docker Build Cloud
Summary
Docker Build Cloud executes builds remotely, necessitating optimizations to mitigate network transfer limitations. Key strategies include utilizing attached storage volumes for build cache and transferring only changed layers. Further optimizations involve using .dockerignore files to exclude unnecessary files from the build context, employing slim base images, leveraging multi-stage builds, fetching remote files within the build process, and using multi-threaded tools. A .dockerignore file is useful for excluding version control history (.git) and local build artifacts.