|
| 1 | +--- |
| 2 | +title: Customize a Docker Hardened Image |
| 3 | +linkTitle: Customize an image |
| 4 | +weight: 25 |
| 5 | +keywords: debug, hardened images, DHI, customize, certificate, artififact |
| 6 | +description: Learn how to customize a Docker Hardened Images (DHI). |
| 7 | +--- |
| 8 | + |
| 9 | +You can customize a Docker Hardened Image (DHI) to suit your specific needs |
| 10 | +using the Docker Hub UI. This allows you to select a base image, add packages, |
| 11 | +add artifacts, and configure settings. In addition, the build pipeline ensures that |
| 12 | +your customized image is built securely and includes attestations. |
| 13 | + |
| 14 | +To add a customized Docker Hardened Image to your organization, you must first |
| 15 | +[mirror](./mirror.md) the DHI repository to your organization. |
| 16 | + |
| 17 | +## Customize a Docker Hardened Image |
| 18 | + |
| 19 | +To customize a Docker Hardened Image, follow these steps: |
| 20 | + |
| 21 | +1. Sign in to [Docker Hub](https://hub.docker.com). |
| 22 | +2. Select **My Hub**. |
| 23 | +3. In the namespace drop-down, select your organization that has a mirrored DHI |
| 24 | + repository. |
| 25 | +4. Select the mirrored DHI repository. |
| 26 | +5. Select the **Customizations** tab. |
| 27 | +6. Select **Create customization**. |
| 28 | + |
| 29 | + At this point, the on-screen instructions will guide you through the |
| 30 | + customization process. You can continue with the following steps for more |
| 31 | + details. |
| 32 | + |
| 33 | +7. Select the image version you want to customize. |
| 34 | +8. Add packages. |
| 35 | + |
| 36 | + 1. In the **Packages** drop-down, select the packages you want to add to the |
| 37 | + image. |
| 38 | + 2. In the **OCI artifacts** drop-down select the OCI artifacts you want to |
| 39 | + add to the image. The OCI artifacts are images that you have previously |
| 40 | + built and pushed to a repository in the same namespace as the mirrored |
| 41 | + DHI. For example, you can add a custom root CA certificate or a another |
| 42 | + image that contains a tool you need, like adding Python to a Node.js |
| 43 | + image. For more details on how to create an OCI artifact image, see |
| 44 | + [Create an OCI artifact image](#create-an-oci-artifact-image). |
| 45 | + |
| 46 | + When combining images that contain directories and files with the same |
| 47 | + path, images later in the list will overwrite files from earlier images. |
| 48 | + To manage this, you can further select paths to include or exclude from |
| 49 | + each OCI artifact image. This allows you to control which files are |
| 50 | + included in the final customized image. |
| 51 | + |
| 52 | + > [!NOTE] |
| 53 | + > |
| 54 | + > When necessary files are overwritten, the image build still |
| 55 | + > succeeds, but you may have issues when running the image. |
| 56 | +
|
| 57 | +9. Select **Next: Configure** and then configure the following options. |
| 58 | + |
| 59 | + 1. Specify a suffix that is appended to the customized image's tag. For |
| 60 | + example, if you specify `custom` when customizing the `dhi-python:3.13` |
| 61 | + image, the customized image will be tagged as `dhi-python:3.13_custom`. |
| 62 | + 2. Select the platforms you want to build the image for. |
| 63 | + 3. Add [`ENTRYPOINT`](/reference/dockerfile/#entrypoint) and |
| 64 | + [`CMD`](/reference/dockerfile/#cmd) arguments to the image. These |
| 65 | + arguments are appended to the base image's entrypoint and command. |
| 66 | + 4. Specify the users to add to the image. |
| 67 | + 5. Specify the user groups to add to the image. |
| 68 | + 6. Select which [user](/reference/dockerfile/#user) to run the images as. |
| 69 | + 7. Specify the [environment variables](/reference/dockerfile/#env) and their |
| 70 | + values that the image will contain. |
| 71 | + 8. Add [annotations](/build/metadata/annotations/) to the image. |
| 72 | + 9. Add [labels](/reference/dockerfile/#label) to the image. |
| 73 | +10. Select **Create Customization**. |
| 74 | + |
| 75 | + A summary of the customization appears. It may take some time for the image |
| 76 | + to build. Once built, it will appear in the **Tags** tab of the repository, |
| 77 | + and your team members can pull it like any other image. |
| 78 | + |
| 79 | +## Edit or delete a Docker Hardened Image customization |
| 80 | + |
| 81 | +To edit or delete a Docker Hardened Image customization, follow these steps: |
| 82 | + |
| 83 | +1. Sign in to [Docker Hub](https://hub.docker.com). |
| 84 | +2. Select **My Hub**. |
| 85 | +3. In the namespace drop-down, select your organization that has a mirrored DHI. |
| 86 | +4. Select the mirrored DHI repository. |
| 87 | +5. Select the **Customizations** tab. |
| 88 | +6. Select **Edit** to edit the customization, or select the trashcan icon to |
| 89 | + delete the customization. |
| 90 | +7. Follow the on-screen instructions to complete the edit or deletion. |
| 91 | + |
| 92 | +## Create an OCI artifact image |
| 93 | + |
| 94 | +An OCI artifact image is a Docker image that contains files or directories that |
| 95 | +you want to include in your customized Docker Hardened Image (DHI). This can |
| 96 | +include additional tools, libraries, or configuration files. |
| 97 | + |
| 98 | +When creating an image to use as an OCI artifact, it should ideally be as |
| 99 | +minimal as possible and contain only the necessary files. |
| 100 | + |
| 101 | +For example, to distribute a custom root CA certificate as part of a trusted CA |
| 102 | +bundle, you can use a multi-stage build. This approach registers your |
| 103 | +certificate with the system and outputs an updated CA bundle, which can be |
| 104 | +extracted into a minimal final image: |
| 105 | + |
| 106 | +```dockerfile |
| 107 | +# syntax=docker/dockerfile:1 |
| 108 | + |
| 109 | +FROM yourorg/dhi-bash:5-dev AS certs |
| 110 | + |
| 111 | +ENV DEBIAN_FRONTEND=noninteractive |
| 112 | + |
| 113 | +RUN mkdir -p /usr/local/share/ca-certificates/my-rootca |
| 114 | +COPY certs/rootCA.crt /usr/local/share/ca-certificates/my-rootca |
| 115 | + |
| 116 | +RUN update-ca-certificates |
| 117 | + |
| 118 | +FROM scratch |
| 119 | +COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt |
| 120 | +``` |
| 121 | + |
| 122 | +You can follow this pattern to create other OCI artifacts, such as images |
| 123 | +containing tools or libraries that you want to include in your customized DHI. |
| 124 | +Install the necessary tools or libraries in the first stage, and then copy the |
| 125 | +relevant files to the final stage that uses `FROM scratch`. This ensures that |
| 126 | +your OCI artifact is minimal and contains only the necessary files. |
| 127 | + |
| 128 | +Build and push the OCI artifact image to a repository in your organization's |
| 129 | +namespace and it automatically appears in the customization workflow when you |
| 130 | +select the OCI artifacts to add to your customized Docker Hardened Image. |
0 commit comments