Skip to content

Conversation

@rich7420
Copy link

@rich7420 rich7420 commented Dec 21, 2025

@adoroszlai
Copy link
Contributor

@rich7420 can you please share image size before/after this change? (Like I mentioned in apache/ozone#9538, deleting files in a separate RUN step does not reduce image size.)

@rich7420
Copy link
Author

rich7420 commented Dec 23, 2025

@adoroszlai , my mistake , I've added a slim dockerfile.
Image │ Logical Size │ Compressed Size
Original │ 2.34GB │ 0.82 GB
Slim │ 1.87GB │ 0.61 GB

Copy link
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

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

Thanks @rich7420 for the patch.

We'll need changes in both docker-ozone-runner and docker-ozone, so I've created subtasks for HDDS-13426. This change would then belong to HDDS-14230, and can be done after HDDS-14229.

It should target the slim branch, editing Dockerfile, so that workflows for CI check and publishing the image to container registries automatically pick it up.

Also, please enable GitHub Actions workflows in your forks of both repos.

Dockerfile.slim Outdated
ARG OZONE_VERSION=2.0.0
ARG OZONE_URL="https://www.apache.org/dyn/closer.lua?action=download&filename=ozone/${OZONE_VERSION}/ozone-${OZONE_VERSION}.tar.gz"

FROM alpine:latest AS extractor
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need the extractor stage, deletion can be added to the existing RUN curl, tar command.

Dockerfile.slim Outdated
curl -LSs -o ozone.tar.gz "$OZONE_URL" && \
tar zxf ozone.tar.gz && \
cd ozone-${OZONE_VERSION} && \
rm -rf docs examples share/doc share/man licenses LICENSE.txt NOTICE.txt README.md HISTORY.md SECURITY.md CONTRIBUTING.md compose kubernetes share/ozone/byteman && \
Copy link
Contributor

Choose a reason for hiding this comment

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

Please list dirs/files to be deleted one per line, in alphabetical order. This makes it easier to understand and reduces diff when making changes later.

I think we should keep licenses LICENSE.txt NOTICE.txt.

Dockerfile.slim Outdated
tar zxf ozone.tar.gz && \
cd ozone-${OZONE_VERSION} && \
rm -rf docs examples share/doc share/man licenses LICENSE.txt NOTICE.txt README.md HISTORY.md SECURITY.md CONTRIBUTING.md compose kubernetes share/ozone/byteman && \
find . -type f \( -name "ozone-filesystem-hadoop2-*.jar" -o -name "ozone-filesystem-hadoop3-*.jar" -o -name "ozone-filesystem-hadoop3-client-*.jar" -o -name "*-tests.jar" -o -name "*-test.jar" -o -name "*test*.jar" -o -name "*-docs-*.jar" -o -name "*-shaded.jar" -o -name "*-all.jar" -o -name "*-fat.jar" \) -delete && \
Copy link
Contributor

Choose a reason for hiding this comment

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

List of ozone-filesystem-hadoop2 etc. can be simplified to ozone-filesystem-hadoop*.jar.

"*test*.jar" covers the other two tests conditions.

Copy link
Author

Choose a reason for hiding this comment

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

oh you're right!

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, "*-shaded.jar", "*-all.jar" and "*-fat.jar" are unnecessary.

Dockerfile.slim Outdated
cd ozone-${OZONE_VERSION} && \
rm -rf docs examples share/doc share/man licenses LICENSE.txt NOTICE.txt README.md HISTORY.md SECURITY.md CONTRIBUTING.md compose kubernetes share/ozone/byteman && \
find . -type f \( -name "ozone-filesystem-hadoop2-*.jar" -o -name "ozone-filesystem-hadoop3-*.jar" -o -name "ozone-filesystem-hadoop3-client-*.jar" -o -name "*-tests.jar" -o -name "*-test.jar" -o -name "*test*.jar" -o -name "*-docs-*.jar" -o -name "*-shaded.jar" -o -name "*-all.jar" -o -name "*-fat.jar" \) -delete && \
find . -type d \( -name "test*" -o -name "tests" -o -name "*test" -o -name "__pycache__" \) -exec rm -rf {} + 2>/dev/null || true && \
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete tests and smoketest in the first rm -rf command above. __pycache__ does not need to be deleted.

Dockerfile.slim Outdated
rm -rf docs examples share/doc share/man licenses LICENSE.txt NOTICE.txt README.md HISTORY.md SECURITY.md CONTRIBUTING.md compose kubernetes share/ozone/byteman && \
find . -type f \( -name "ozone-filesystem-hadoop2-*.jar" -o -name "ozone-filesystem-hadoop3-*.jar" -o -name "ozone-filesystem-hadoop3-client-*.jar" -o -name "*-tests.jar" -o -name "*-test.jar" -o -name "*test*.jar" -o -name "*-docs-*.jar" -o -name "*-shaded.jar" -o -name "*-all.jar" -o -name "*-fat.jar" \) -delete && \
find . -type d \( -name "test*" -o -name "tests" -o -name "*test" -o -name "__pycache__" \) -exec rm -rf {} + 2>/dev/null || true && \
find . -type f \( -name "*.md" -o -name "*.txt" -o -name "*.pyc" \) ! -path "*/etc/*" ! -path "*/bin/*" ! -path "*/sbin/*" ! -path "*/libexec/*" -delete 2>/dev/null || true
Copy link
Contributor

Choose a reason for hiding this comment

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

This command is not needed.

@adoroszlai adoroszlai changed the base branch from latest to slim December 23, 2025 08:30
@adoroszlai adoroszlai changed the title HDDS-13426. Trim Ozone docker image size HDDS-14230. Create slim ozone image Dec 23, 2025
@adoroszlai adoroszlai marked this pull request as draft December 23, 2025 08:30
@rich7420
Copy link
Author

@adoroszlai thanks for the support!

@rich7420
Copy link
Author

Here's the latest result.
Size: 1.88GB
Compressed: 0.62 GB

@rich7420 rich7420 marked this pull request as ready for review December 23, 2025 08:56
@rich7420 rich7420 marked this pull request as draft December 23, 2025 08:57
Dockerfile.slim Outdated
# limitations under the License.

ARG OZONE_RUNNER_IMAGE=apache/ozone-runner
ARG OZONE_RUNNER_VERSION=20250410-1-jdk21
Copy link
Contributor

Choose a reason for hiding this comment

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

Now this can be set to 20251225-1-jdk21-slim to use the smaller base image.

Dockerfile.slim Outdated
Comment on lines 44 to 51
sudo find . -type f \( \
-name "*-all.jar" -o \
-name "*-docs-*.jar" -o \
-name "*-fat.jar" -o \
-name "*-shaded.jar" -o \
-name "*test*.jar" -o \
-name "ozone-filesystem-hadoop*.jar" \
\) -delete
Copy link
Contributor

Choose a reason for hiding this comment

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

all, fat, shaded and test are unnecessary.

We can replace find with plain delete, because jars are in a single directory.

share/ozone/lib/*-docs-*.jar \
share/ozone/lib/ozone-filesystem-hadoop*.jar \

Dockerfile.slim Outdated
Comment on lines 39 to 40
share/doc \
share/man \
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see these in the tarball, are they necessary?

Copy link
Author

Choose a reason for hiding this comment

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

yap, those are unnecessary

@adoroszlai adoroszlai marked this pull request as ready for review December 26, 2025 08:09
@adoroszlai adoroszlai merged commit 1ad65f1 into apache:slim Dec 26, 2025
2 checks passed
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.

2 participants