> For the complete documentation index, see [llms.txt](https://docs.earthbuild.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.earthbuild.dev/docs/guides/using-the-earthbuild-docker-images/all-in-one.md).

# earthbuild/earthbuild

This image contains `earth`, `buildkit`, and some extra configuration to enable the two to work together. All that's missing is your source code! This image is mainly intended for use in containerized CI scenarios, or where maintaining a persistent installation of `earth` isn't possible.

### Tags

Currently, the `latest` tag is `v0.8.19`. For other available tags, please check out <https://hub.docker.com/r/earthbuild/earthbuild/tags>

### Quickstart

Want to get started? Here are a couple sample `docker run` commands that cover the most common use-cases:

#### Usage with Docker Socket

This example shows how to use the EarthBuild container in conjunction with a Docker socket that EarthBuild can use to start up the BuildKit daemon.

```bash
docker run -t -v $(pwd):/workspace -v /var/run/docker.sock:/var/run/docker.sock -e NO_BUILDKIT=1 earthbuild/earthbuild:v0.8.19 +for-linux
```

Here's a quick breakdown:

* `-t` tells Docker to emulate a TTY. This makes the `earth` log output colorized.
* `-v $(pwd):/workspace` mounts the source code into the conventional location within the docker container. EarthBuild is executed from this directory when starting the container. Any artifacts saved within this folder remain on your local machine.
* `-v /var/run/docker.sock:/var/run/docker.sock` mounts the Docker socket such that EarthBuild can start BuildKit as a Docker container in the host's Docker.
* `-e NO_BUILDKIT=1` tells the EarthBuild container not to start en embedded BuildKit. A BuildKit daemon will instead be started via the Docker socket provided.
* `+for-linux` is the target to be invoked. All arguments specified after the image tag will be passed to `earth`.

#### Usage with Embedded BuildKit

This example shows how the EarthBuild image can start a BuildKit daemon within the same container. A Docker socket is not needed in this case, however the container will need to be run with the `--privileged` flag.

```bash
docker run --privileged -t -v $(pwd):/workspace -v earthbuild-tmp:/tmp/earthbuild:rw earthbuild/earthbuild:v0.8.19 +for-linux
```

Here's a quick breakdown:

* `--privileged` is required when you are using the internal, embedded `buildkit`. This is because `buildkit` currently requires it for OverlayFS support and for network configuration.
* `-t` tells Docker to emulate a TTY. This makes the `earth` log output colorized.
* `-v $(pwd):/workspace` mounts the source code into the conventional location within the docker container. EarthBuild is executed from this directory when starting the container. Any artifacts saved within this folder remain on your local machine.
* `-v earthbuild-tmp:/tmp/earthbuild:rw` mounts (and creates, if necessary) the `earthbuild-tmp` Docker volume into the containers `/tmp/earthbuild`. This is used as a temporary/working directory for `buildkitd` during builds.
* `+for-linux` is the target to be invoked. All arguments specified after the image tag will be passed to `earth`.

### Using This Image

#### Requirements

There are a couple requirements this image expects you to follow when using it. These requirements streamline usage of the image and save configuration effort.

**Privileged Mode**

If you are using the embedded `buildkitd`, then this image needs to be run as a privileged container. This is because `buildkitd` needs appropriate access to use `overlayfs`.

**`/tmp/earthbuild`**

Because this folder sees *a lot* of traffic, its important that it remains fast. We *strongly* recommend using a Docker volume for mounting `/tmp/earthbuild`. If you do not, `buildkitd` can consume excessive disk space, operate very slowly, or it might not function correctly.

In some environments, not mounting `/tmp/earthbuild` as a Docker volume results in the following error:

```
--> WITH DOCKER RUN --privileged ...
...
rm: can't remove '/var/earthbuild/dind/...': Resource busy
```

**Source Mounting**

Because `earth` is running inside a container, it does not have access to your source code unless you grant it. This image expects to find a valid `Earthfile` in the working directory, which is set by default to `/workspace`.

**DOCKER\_HOST**

This image *does* include a functional Docker CLI, but does not include a full Docker daemon. If your `Earthfile` requires a Docker daemon of any sort, you will need to provide it through this environment variable.

If your daemon is on the same host as this container, you can also volume mount your hosts docker daemon using `-v /var/run/docker.sock:/var/run/docker.sock`. Note that this will cause `earth` to use your hosts Docker daemon, and could lead to name conflicts if multiple copies of this image are run on the same host.

**-t**

This is the easiest way to ensure you get the nice, colorized output from `earth`. Alternatively, you could provide the `FORCE_COLOR` environment variable.

#### Supported Environment Variables

| Variable Name                       | Default Values                 | Description                                                                                                                                                                                                   |
| ----------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| GLOBAL\_CONFIG                      |                                | Any valid YAML for the top-level `global` key in `config.yml`. Example: `{local_registry_host: 'tcp://127.0.0.1:8371'}`                                                                                       |
| GIT\_CONFIG                         |                                | Any valid YAML for the top-level `git` key in `config.yml`. Example: `{example: {pattern: 'example.com/([^/]+)', substitute: 'ssh://git@example.com:2222/var/git/repos/$1.git', auth: ssh}}`                  |
| NO\_BUILDKIT                        |                                | Disables the embedded BuildKit daemon.                                                                                                                                                                        |
| DOCKER\_HOST                        | `/var/run/docker.sock`         | From Docker's CLI.                                                                                                                                                                                            |
| BUILDKIT\_HOST                      | `tcp://<hostname>:8372`        | The address of your BuildKit host. Use this when you have a remote `buildkitd` you would like to connect to.                                                                                                  |
| EARTH\_ADDITIONAL\_BUILDKIT\_CONFIG |                                | Additional `buildkitd` config to append to the generated configuration file.                                                                                                                                  |
| BUILDKIT\_TCP\_TRANSPORT\_ENABLED   |                                | Required to be set to `true` when using an external `buildkitd` via `BUILDKIT_HOST`. `true` when using the embedded `buildkitd`.                                                                              |
| BUILDKIT\_TLS\_ENABLED              |                                | Required when using an external `buildkitd` via `BUILDKITD_HOST`, and the external `buildkitd` requires mTLS. You will also need to mount certificates into the right place (`/etc/.earth/certs`).            |
| CNI\_MTU                            | MTU of first default interface | Set this when we autodetect the MTU incorrectly. The device used for autodetection can be shown by the command `ip route show \| grep default \| cut -d' ' -f5 \| head -n 1`                                  |
| EARTH\_RESET\_TMP\_DIR              | `false`                        | Cleans out `/tmp/earthbuild` before running, if set to `true`. Useful when you host-mount an temporary directory across runs.                                                                                 |
| NETWORK\_MODE                       | `cni`                          | Specifies the networking mode of `buildkitd`. Default uses a CNI bridge network, configured with the `CNI_MTU`.                                                                                               |
| CACHE\_SIZE\_MB                     | `0`                            | How big should the `buildkitd` cache be allowed to get, in MiB? A value of 0 sets the cache size to "adaptive", causing BuildKit to detect the available size of the system and choose a limit automatically. |
| GIT\_URL\_INSTEAD\_OF               |                                | Configure `git config --global url.<url>.insteadOf` rules to be used by `buildkitd`.                                                                                                                          |
| IP\_TABLES                          |                                | Override which binary (`iptables_nft` or `iptables_legacy`) is used for configuring `ip_tables`. Only set this if autodetection fails for your platform.                                                      |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.earthbuild.dev/docs/guides/using-the-earthbuild-docker-images/all-in-one.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
