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

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

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

댓글을 달려면 로그인하십시오.

답변 (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!

카테고리

도움말 센터File Exchange에서 Microservices에 대해 자세히 알아보기

질문:

2025년 3월 30일

댓글:

2025년 5월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by