Skip to content

Commit c5bc2dd

Browse files
dhi: env vars in customizations (#25285)
<!--Delete sections as needed --> ## Description Documented how environment variables from OCI artifacts are automatically merged into customized DHI images. Preview: https://deploy-preview-25285--docsdocker.netlify.app/dhi/how-to/customize/ ## Related issues or tickets DXT-775 ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [ ] Editorial review - [ ] Product review --------- Signed-off-by: Craig Osterhout <craig.osterhout@docker.com>
1 parent 140b37a commit c5bc2dd

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

content/manuals/dhi/how-to/customize.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ You can create customizations using either the DHI CLI or the Docker Hub web int
8181
built and pushed to a repository in the same namespace as the mirrored
8282
DHI. For example, you can add a custom root CA certificate or another
8383
image that contains a tool you need, like adding Python to a Node.js
84-
image. For more details on how to create an OCI artifact image, see
85-
[Create an OCI artifact image](#create-an-oci-artifact-image).
84+
image.
8685

8786
You can add multiple OCI artifact images to a single customization. When
8887
you add more than one, they're applied in the order you add them in the
@@ -102,6 +101,8 @@ You can create customizations using either the DHI CLI or the Docker Hub web int
102101
> image build still succeeds, but you may have issues when running the
103102
> image.
104103
104+
For more details, see [OCI artifacts](#oci-artifacts).
105+
105106
1. In the **Scripts** section, you can add, edit, or remove scripts.
106107

107108
Scripts let you add files to the container image that you can access at runtime. They are not executed during
@@ -351,8 +352,9 @@ contents:
351352
| `includes` | Paths to copy from the artifact. No files are included by default. You must list at least one path. |
352353
| `excludes` | Paths to exclude after applying `includes`. |
353354

354-
For instructions on building an OCI artifact image, see
355-
[Create an OCI artifact image](#create-an-oci-artifact-image).
355+
To learn more about OCI artifacts, including how to create them, best
356+
practices, and how environment variables behave, see
357+
[OCI artifacts](#oci-artifacts).
356358

357359
#### Inject files into the image
358360

@@ -481,14 +483,16 @@ tooling.
481483
compression: ZSTD
482484
```
483485

484-
### Create an OCI artifact image
486+
## OCI artifacts
485487

486-
An OCI artifact image is a Docker image that contains files or directories that
487-
you want to include in your customized Docker Hardened Image (DHI). This can
488-
include additional tools, libraries, or configuration files.
488+
In DHI customization, OCI artifacts are Docker images containing files you
489+
want to layer into your image, such as custom certificates, internal tools, or
490+
configuration files.
491+
492+
### Create an OCI artifact image
489493

490-
When creating an image to use as an OCI artifact, it should ideally be as
491-
minimal as possible and contain only the necessary files.
494+
Keep artifact images as minimal as possible and include only the necessary
495+
files.
492496

493497
For example, to distribute a custom root CA certificate as part of a trusted CA
494498
bundle, you can use a multi-stage build. This approach registers your
@@ -545,13 +549,31 @@ Once pushed to a repository in your organization's namespace, the OCI artifact
545549
automatically appears in the customization workflow when you select OCI
546550
artifacts to add to your customized Docker Hardened Image.
547551

548-
#### Best practices for OCI artifacts
552+
### Environment variables
553+
554+
When you include OCI artifacts in a customization, the environment variables
555+
defined in those artifacts are merged into the final image. The merge follows
556+
these rules:
557+
558+
- Your customization's environment settings take precedence. An artifact's
559+
variable is only applied if the corresponding key is absent or empty in your
560+
customization.
561+
- `PATH` is an exception. Artifact `PATH` entries are added to the front of
562+
the existing `PATH`, giving them runtime precedence.
563+
564+
This differs from `COPY --from` in a Dockerfile, which copies files without
565+
inheriting environment variables from the source image. To avoid inheriting
566+
environment variables, build the artifact using a `FROM scratch` final stage.
567+
See [Create an OCI artifact image](#create-an-oci-artifact-image).
568+
569+
### Best practices
549570

550571
Follow these best practices when creating OCI artifacts for DHI customizations:
551572

552573
- Use multi-stage builds: Build or install dependencies in a builder stage,
553574
then copy only the necessary files to a `FROM scratch` final stage. This keeps
554-
the OCI artifact minimal and free of unnecessary build tools.
575+
the OCI artifact minimal and avoids inheriting environment variables from the
576+
builder image into your customization.
555577

556578
- Include only essential files: OCI artifacts should contain only the files
557579
you need to add to the customized image. Avoid including package managers,

0 commit comments

Comments
 (0)