Skip to content
MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
MathWorks
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out

Videos and Webinars

  • MathWorks
  • Videos
  • Videos Home
  • Search
  • Videos Home
  • Search
  • Contact sales
  • Trial software
5:23 Video length is 5:23.
  • Description
  • Full Transcript
  • Related Resources

Use MATLAB Compiler to Package Standalone Applications into Docker Containers

A new feature in MATLAB Compiler™ R2020b lets you package your standalone applications into Docker container images. This allows your applications to be easily distributed and shared throughout your organization as well as in the cloud. The Docker container is completely self-contained and consists of operating system libraries, a MATLAB® Runtime optimized to run your application, and the application itself.

I want to tell you about a new feature in MATLAB compiler R2020B-- the ability to package your standalone applications as Docker container images. Now, the altering of the packaging must be performed from a Linux environment. However, the resulting Docker container can be run in Linux, Windows, or the Mac.

Note that UI based applications require an X-windows server, which is only natively supported on Linux. Some people have been successful using options like VcXsrv or Cygwin on Windows, as well as XQuartz on Mac OS. But these options are not fully tested and qualified at MathWorks. So your mileage may vary.

How does this all work? Well, a MATLAB user packages their standalone application using MATLAB compiler, and targets a Docker container image. Now this Docker container image that is created contains several layers. The first layer contains the operating system-- in this case, Linux libraries-- followed by a layer with the optimized MATLAB Runtime containing just the components and tool boxes that you have used in your code.

And then finally, there is an application executable layer. This topic container image is saved onto your local repository in your PC. And at some point, this container may be passed on to your IT department, which posts it into a corporate registry. The users in your organization can browse this registry. And at some point in time, may decide to run it using the Docker run command.

There are many benefits to packaging and distributing your applications as Docker containers. It is a consistent environment with all the dependencies pre-installed in it. And it's very easily distributed through the registry and very easily executed. Let's see how we can create a Docker container image using MATLAB compiler.

The first thing we need to do is to make sure that the MATLAB Runtime has been downloaded. And we can do so using the compiler dot runtime dot download command. If you have already downloaded the MATLAB Runtime, you will not have to perform this task again a second time.

We're going to take our magic square function here and generate a Docker container image. This is a very simple function that takes a single numeric input and returns a magic square. The first step we need to do is to compile this into a standalone application. And we do so using the compiler dot bill dot standalone application command, passing in the name of our M file and telling it to treat the inputs as numeric.

This standalone application is saved into the magic app variable. Once we have that, we can then call the compiler dot package dot Docker command, and pass in the name of our newly generated standalone application, as well as telling it to name the Docker image magic dash hat. Take note that Docker image names need to be all lowercase.

Now, this process might take longer if you are doing this for the first time, because the packaging process needs to create the underlying operating system library layers, as well as the underlying runtime layers. I have previously generated these, so my process took a lot quicker. Once this process finishes running, you will be provided with the Docker run command needed to execute your application.

Copy this into your clipboard. Note that you have to run x host plus if you want to run MATLAB app designer UI applications. Let's switch over to the terminal window to run our newly generated magic square container. We will first enter the x host plus command, followed by pasting in the Docker run command that we copied from MATLAB compiler.

Don't forget to provide the input parameter-- in this case 5. The Docker container runs and outputs the 5 by 5 magic square. Now, you might be wondering if you can run MATLAB App Designer UI apps. And the answer is yes. I'll run a container I packaged earlier with a UI app.

This is an application that runs a Simulink model of a mass spring damper generated with the help of Simulink compiler. As you can see, it runs just like a typical, standalone UI app. If you want to learn more about how to use Docker containers, please visit the Help pages found in the MATLAB compiler documentation.

Related Products

  • MATLAB Compiler

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper
Related Information
Related Information
Get MATLAB Compiler

Feedback

Featured Product

MATLAB Compiler

  • Request Trial
  • Get Pricing

Up Next:

3:58
Getting Started: Standalone Applications Using MATLAB...

Related Videos:

2:23
What Is MATLAB Compiler?
3:19
Getting Started: Excel Add-ins Using MATLAB Compiler
26:14
Sharing and Deploying MATLAB Applications
1:04:54
Automated Trading with MATLAB

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contact sales
  • Trial software

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover…

Explore Products

  • MATLAB
  • Simulink
  • Student Software
  • Hardware Support
  • File Exchange

Try or Buy

  • Downloads
  • Trial Software
  • Contact Sales
  • Pricing and Licensing
  • How to Buy

Learn to Use

  • Documentation
  • Tutorials
  • Examples
  • Videos and Webinars
  • Training

Get Support

  • Installation Help
  • MATLAB Answers
  • Consulting
  • License Center
  • Contact Support

About MathWorks

  • Careers
  • Newsroom
  • Social Mission
  • Customer Stories
  • About MathWorks
  • Select a Web Site United States
  • Trust Center
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status

© 1994-2022 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Join the conversation