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