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 个)

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 CenterFile Exchange 中查找有关 Nonlinear 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