Skip to content

Install packages without docs to reduce image size - #897

Open
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:fix/install-packages-nodocs
Open

Install packages without docs to reduce image size#897
abrarshivani wants to merge 1 commit into
NVIDIA:mainfrom
abrarshivani:fix/install-packages-nodocs

Conversation

@abrarshivani

@abrarshivani abrarshivani commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Closes #773

What

Set tsflags=nodocs once per RHEL image so dnf stops writing documentation and man pages into the layers we ship.

Why

The UBI bases don't set tsflags in /etc/dnf/dnf.conf, so every dnf install/dnf update we run installs documentation with the package. It grows the image and gets flagged by CI scanners — #772 hit this with perl docs containing sample secrets. The bases themselves are clean, so the docs all come from our own install steps.

How

Folded into the first dnf transaction of each image, so everything after it inherits the setting: the installs in install.sh, the CVE_UPDATES blocks, and the dnf install calls nvidia-driver and ocp_dtk_entrypoint make when the container starts. Passing --nodocs per command would have missed those and needed the flag on ~46 call sites.

Each Dockerfile only handles the bases it is actually built with, and the value is written through dnf's own config writer rather than by editing the file:

Dockerfile bases config-manager tsflags before what it does
rhel9, rhel10 ubi9/10, rockylinux 9.8/10.2 ubi only rocky only configure unless already set
rhel8 ubi8, rockylinux 8.10 ubi only neither install it if absent, then configure
vgpu-manager/rhel8, rhel9 CUDA UBI, fixed yes none configure

Installing config-manager costs about 4 MiB and only happens on rockylinux 8, which is close to end of life. Everywhere else it is already present.

Notes

  • Ubuntu needs no change: its bases ship /etc/dpkg/dpkg.cfg.d/excludes, which already drops /usr/share/doc and /usr/share/man. This is RHEL only.
  • rm -rf /usr/share/doc/* in install.sh stays. nodocs doesn't cover files shipped without a %doc marker or written outside rpm.
  • The vGPU Manager images build on nvcr.io/nvidia/cuda:*-base-ubi8/9, which already has documentation in its parent layers. This only stops documentation from the transactions we run.
  • install_weak_deps=False left out: it's what actually kept the perl docs out in avoid installing docs in image #772, but it can silently drop a package needed at runtime. Possible follow up.

Testing

Verified on every base image that the change lands on tsflags=nodocs: ubi8, ubi9, ubi10, rockylinux 8.10/9.8/10.2-ubi, and the CUDA UBI 8 and 9 bases.

Built for driver 580.178.04, each pair back to back with --no-cache so both resolve the same packages:

before after saved
rhel9 752,585,630 740,277,958 11.74 MiB (1.64%)
rocky8 832,220,952 815,087,316 16.34 MiB (2.06%)

rocky8 saves more despite installing config-manager, because it starts with more documentation. In its filesystem /usr/share/man goes from 1289 files to 1 (a dangling symlink) and /usr/share/info from 32 to 1, while all 226 /usr/share/licenses files are untouched. /usr/share/doc is empty either way, since the existing rm -rf already cleared it. rhel9 behaves the same, with its 237 license files intact.

@abrarshivani
abrarshivani force-pushed the fix/install-packages-nodocs branch 8 times, most recently from aaab24e to a301308 Compare August 4, 2026 02:21
@abrarshivani abrarshivani self-assigned this Aug 4, 2026
@abrarshivani
abrarshivani force-pushed the fix/install-packages-nodocs branch from a301308 to b102cbc Compare August 4, 2026 03:18
@abrarshivani
abrarshivani marked this pull request as ready for review August 4, 2026 03:22
Comment thread tests/check-nodocs.sh Outdated
@rahulait

rahulait commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Thanks @abrarshivani. This change LGTM, lets wait for some time before we merge this PR as we don't want these changes to affect existing release in progress.

@abrarshivani
abrarshivani force-pushed the fix/install-packages-nodocs branch from b102cbc to 0e1cf09 Compare August 4, 2026 20:00
@abrarshivani

Copy link
Copy Markdown
Contributor Author

@rahulait Sounds good. Let's merge this after release.

@tariq1890

Copy link
Copy Markdown
Contributor

What is the difference in image size before and after this change?

@abrarshivani

Copy link
Copy Markdown
Contributor Author

What is the difference in image size before and after this change?

@tariq1890 Following are difference in image sizes:

rhel9 images for driver:

amd64 arm64
before 737,276,803 629,866,665
after 726,017,362 618,596,702
saved 10.74 MiB (1.53%) 10.75 MiB (1.79%)

Comment thread .github/workflows/image.yaml Outdated
- release-*

jobs:
check-nodocs:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary. If we want to establish a policy of never downloading docs when building images, we could explore that separately. For now, we don't have to add an extra step to our CIs

Comment thread rhel10/Dockerfile Outdated
SHELL ["/bin/bash", "-c"]

RUN dnf update -y && dnf clean all
RUN dnf update -y --nodocs && dnf clean all

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we disable docs in a dnf.conf file so that we express this preference once instead of doing so in every dnf command?

@abrarshivani
abrarshivani force-pushed the fix/install-packages-nodocs branch 3 times, most recently from 7a69aca to b222616 Compare September 1, 2026 01:19
The UBI base images do not set tsflags in /etc/dnf/dnf.conf, so every dnf
install and dnf update we run installs documentation and man pages into
the layers we ship. They grow the image for no runtime benefit and get
picked up by CI scanners; NVIDIA#772 hit this when the perl docs pulled in by
git were flagged for containing sample secrets.

Set tsflags=nodocs once per RHEL image, before the first dnf transaction,
so every later call inherits it. That covers the installs in install.sh
and the CVE_UPDATES blocks, and also the ones nvidia-driver and
ocp_dtk_entrypoint run when the container starts, which passing --nodocs
per command would have missed.

The bases differ in what they provide, so the value is written through
dnf's own config writer rather than by editing the file directly:

  rockylinux 9.8-ubi and 10.2-ubi already ship tsflags=nodocs, so nothing
  is done; ubi8, ubi9, ubi10 and the CUDA UBI bases have config-manager
  preinstalled; rockylinux 8.10-ubi has neither and installs it first.

Installing config-manager costs about 4 MiB and only happens on
rockylinux 8, which is close to end of life. Everywhere else it is free.

Signed-off-by: Abrar Shivani <ashivani@nvidia.com>
@abrarshivani
abrarshivani force-pushed the fix/install-packages-nodocs branch from b222616 to d326d5c Compare September 1, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] : install packages without docs to reduce size and avoid things which are not needed

4 participants