Skip to main content
Version: 2.18 (deprecated)

docker_environment


Configuration of a Docker environment used for building your code.

Environment configuration includes both Docker-specific information (including the image and platform choice), as well as environment-aware options (such as environment variables and search paths) used by Pants to execute processes in this Docker environment.

To use this environment, map this target's address with a memorable name in [environments-preview].names. You can then consume this environment by specifying the name in the environment field defined on other targets.

Before running Pants using this environment, if you are using Docker Desktop, make sure the option Enable default Docker socket is enabled, you can find it in Docker Desktop Settings > Advanced panel. That option tells Docker to create a socket at /var/run/docker.sock which Pants can use to communicate with Docker.

Backend: pants.core


image

str
required

The docker image ID to use when this environment is loaded.

This value may be any image identifier that the local Docker installation can accept. This includes image names with or without tags (e.g. centos6 or centos6:latest), or image names with an immutable digest (e.g. centos@sha256:<some_sha256_value>).

The choice of image ID can affect the reproducibility of builds. Consider using an immutable digest if reproducibility is needed, but regularly ensure that the image is free of relevant bugs or security vulnerabilities.

Note that in order to use an image as a docker_environment it must have a few tools: - /bin/sh - /usr/bin/env - bash - tar

While most images will have these preinstalled, users of base images such as Distroless or scratch will need to bake these tools into the image themselves. All of these except bash are available via busybox.

apache_thrift_thrift_search_paths

Iterable[str] | None
default: None
backend: pants.backend.codegen.thrift.apache.python

Overrides the default value from the option [apache-thrift].thrift_search_paths when this environment target is active.

description

str | None
default: None

A human-readable description of the target.

Use pants list --documented :: to see all targets with descriptions.

docker_env_vars

Iterable[str] | None
default: None
backend: pants.backend.docker

Overrides the default value from the option [docker].env_vars when this environment target is active.

docker_executable_search_paths

Iterable[str] | None
default: None
backend: pants.backend.docker

Overrides the default value from the option [docker].executable_search_paths when this environment target is active.

fallback_environment

str | None
default: None

The environment to fallback to when this Docker environment cannot be used because either the global option --docker-execution is false, or the field platform is not compatible with the local host's CPU architecture (this is only an issue when the local host is Linux; macOS is fine).

Must be an environment name from the option [environments-preview].names, the special string __local__ to use the relevant local environment, or the Python value None to error when this specific Docker environment cannot be used.

go_generate_env_vars

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [go-generate].env_vars when this environment target is active.

golang_cgo_c_flags

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_c_flags when this environment target is active.

golang_cgo_cxx_flags

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_cxx_flags when this environment target is active.

golang_cgo_fortran_binary_name

str | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_fortran_binary_name when this environment target is active.

golang_cgo_fortran_flags

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_fortran_flags when this environment target is active.

golang_cgo_gcc_binary_name

str | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_gcc_binary_name when this environment target is active.

golang_cgo_gxx_binary_name

str | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_gxx_binary_name when this environment target is active.

golang_cgo_linker_flags

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_linker_flags when this environment target is active.

golang_cgo_tool_search_paths

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].cgo_tool_search_paths when this environment target is active.

golang_external_linker_binary_name

str | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].external_linker_binary_name when this environment target is active.

golang_go_search_paths

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].go_search_paths when this environment target is active.

golang_subprocess_env_vars

Iterable[str] | None
default: None
backend: pants.backend.experimental.go

Overrides the default value from the option [golang].subprocess_env_vars when this environment target is active.

jvm_global_options

Iterable[str] | None
default: None
backend: pants.backend.experimental.java

Overrides the default value from the option [jvm].global_options when this environment target is active.

nodejs_corepack_env_vars

Iterable[str] | None
default: None
backend: pants.backend.experimental.javascript

Overrides the default value from the option [nodejs].corepack_env_vars when this environment target is active.

nodejs_executable_search_paths

Iterable[str] | None
default: None
backend: pants.backend.experimental.javascript

Overrides the default value from the option [nodejs].executable_search_paths when this environment target is active.

nodejs_search_path

Iterable[str] | None
default: None
backend: pants.backend.experimental.javascript

Overrides the default value from the option [nodejs].search_path when this environment target is active.

pex_executable_search_paths

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [pex].executable_search_paths when this environment target is active.

platform

'linux_arm64' | 'linux_x86_64' | 'macos_arm64' | 'macos_x86_64' | None
default: None

If set, Docker will always use the specified platform when pulling and running the image.

If unset, Pants will default to the CPU architecture of your local host machine. For example, if you are running on Apple Silicon, it will use linux_arm64, whereas running on Intel macOS will use linux_x86_64. This mirrors Docker's behavior when --platform is left off.

pyenv_python_provider_installation_extra_env_vars

Iterable[str] | None
default: None
backend: pants.backend.python.providers.experimental.pyenv

Overrides the default value from the option [pyenv-python-provider].installation_extra_env_vars when this environment target is active.

python_bootstrap_names

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [python-bootstrap].names when this environment target is active.

python_bootstrap_search_path

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [python-bootstrap].search_path when this environment target is active.

python_native_code_cpp_flags

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [python-native-code].cpp_flags when this environment target is active.

python_native_code_ld_flags

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [python-native-code].ld_flags when this environment target is active.

shell_setup_executable_search_paths

Iterable[str] | None
default: None
backend: pants.backend.shell

Overrides the default value from the option [shell-setup].executable_search_paths when this environment target is active.

subprocess_environment_env_vars

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [subprocess-environment].env_vars when this environment target is active.

tags

Iterable[str] | None
default: None

Arbitrary strings to describe a target.

For example, you may tag some test targets with 'integration_test' so that you could run pants --tag='integration_test' test :: to only run on targets with that tag.

test_extra_env_vars

Iterable[str] | None
default: None
backend: pants.core

Overrides the default value from the option [test].extra_env_vars when this environment target is active.