How can I reduce the size and startup time of Docker images generated with compiler.p​ackage.mic​roserviceD​ockerImage​?

7 ビュー (過去 30 日間)
I'm using MATLAB R2024b with compiler.build.productionServerArchive and compiler.package.microserviceDockerImage to generate Docker containers for microservices.
I’m customizing the Dockerfile using the AdditionalInstructions parameter to install extra Java libraries (e.g., commons-io.jar, commons-compress.jar). Here’s an excerpt of the relevant code:
result = compiler.build.productionServerArchive(stages,'ArchiveName',archiveName);
compiler.package.microserviceDockerImage(result, 'ImageName', imageName);
The problem is:
  • The final Docker image is too large and slow to start.
  • I’m not sure what parts of the MATLAB-generated runtime are essential or which ones I can safely remove.
  • There is little documentation on optimizing the generated microservice images.
What I’ve tried:
  • Specifying RuntimeImage (e.g., ubuntu:24.10 or mathworks/matlab-runtime).
  • Cleaning up apt caches.
  • Reviewing official documentation and forums.
What I want to know:
  • How can I reduce the size of the Docker image generated by compiler.package.microserviceDockerImage?
  • Can I use a slim runtime image safely, or remove parts of the MATLAB runtime?
  • Is there an official or recommended way to increase performance and minimize startup time?
Thanks in advance!
  1 件のコメント
Wesley
Wesley 2025 年 5 月 5 日

Just curious, what size and startup times are you seeing now? And what kind of workflow is your container doing?

サインインしてコメントする。

回答 (1 件)

Zinea
Zinea 2025 年 4 月 1 日
The Docker runtime image built during the deployment of microservices or standalone applications already includes only the minimal Runtime products required to run the compiled code.
To exclude functions that are not invoked in deployed applications, you can use the exclude pragma (https://www.mathworks.com/help/compiler/exclude.html).
Hope this helps, best!

カテゴリ

Help Center および File ExchangeNonlinear Least Squares (Curve Fitting) についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by