Main Content

compiler.package.MicroserviceDockerImageOptions

Create a microservice Docker options object

Description

example

Caution

This function is only supported on Linux® operating systems.

opts = compiler.package.MicroserviceDockerImageOptions(results) creates a MicroserviceDockerImageOptions object opts using the compiler.build.Results object results. The Results object is created by the compiler.build.productionServerArchive function. Pass the MicroserviceDockerImageOptions object as an input to the compiler.package.docker function to specify build options.

example

opts = compiler.package.MicroserviceDockerImageOptions(results,Name,Value) creates a MicroserviceDockerImageOptions object opts using the compiler.build.Results object results and additional options specified as one or more pairs of name-value arguments. Options include the build folder, entry point command, and image name.

example

opts = compiler.package.MicroserviceDockerImageOptions('ImageName',imageName) creates a default MicroserviceDockerImageOptions object with the image name specified by imageName.

example

opts = compiler.package.MicroserviceDockerImageOptions('ImageName',imageName,Name,Value) creates a generic MicroserviceDockerImageOptions object with the image name specified by imageName and additional options specified as one or more pairs of name-value arguments.

Examples

collapse all

Create a MicroserviceDockerImageOptions object using the build results from a production server archive on a Linux system.

Create a production server archive using magicsquare.m and save the build results to a compiler.build.Results object.

appFile = fullfile(matlabroot,'extern','examples','compiler','magicsquare.m');
buildResults = compiler.build.productionServerArchive(appFile);

Create a MicroserviceDockerImageOptions object using the build results from the compiler.build.productionServerArchive function.

opts = compiler.package.MicroserviceDockerImageOptions(buildResults);

You can modify property values of an existing MicroserviceDockerImageOptions object using dot notation. For example, set the build folder.

opts.DockerContext = './myDockerFiles';

Pass the MicroserviceDockerImageOptions and Results objects as inputs to the compiler.package.microserviceDockerImage function to build the microservice Docker® image.

compiler.package.microserviceDockerImage(buildResults,'Options',opts);

Create a MicroserviceDockerImageOptions object using build results from a production server archive and customize it using name-value arguments.

Create a production server archive using magicsquare.m and save the build results to a compiler.build.Results object.

appFile = fullfile(matlabroot,'extern','examples','compiler','magicsquare.m');
buildResults = compiler.build.productionServerArchive(appFile);

Create a MicroserviceDockerImageOptions object using the build results from the compiler.build.productionServerArchive function. Use name-value arguments to specify the image name and build folder.

opts = compiler.package.MicroserviceDockerImageOptions(buildResults, ...
'DockerContext','Docker/MagicSquareMicroservice', ...
'ImageName','magicsquare-microservice-');
opts = 

  MicroserviceDockerImageOptions with properties:

    ExecuteDockerBuild: on
             ImageName: 'magic-square-'
         DockerContext: './Docker/MagicSquareMicroservice/magicsquare-microservice-docker'

Create a generic MicroserviceDockerImageOptions object by only specifying the image name.

Create a MicroserviceDockerImageOptions object.

opts = compiler.package.MicroserviceDockerImageOptions('ImageName','helloworld')
opts = 

  MicroserviceDockerImageOptions with properties:

    ExecuteDockerBuild: on
             ImageName: 'helloworld'
         DockerContext: './helloworlddocker'

Create a MicroserviceDockerImageOptions object using the image name and customize it using name-value arguments.

Create a MicroserviceDockerImageOptions object. Use name-value arguments to specify the image name and build folder.

opts = compiler.package.MicroserviceDockerImageOptions('ImageName','myapp', ...
'DockerContext','Docker/MyDockerApp')
opts = 

  MicroserviceDockerImageOptions with properties:

    ExecuteDockerBuild: on
             ImageName: 'myapp'
         DockerContext: './Docker/MyDockerApp'

Input Arguments

collapse all

Build results from the compiler.build.productionServerArchive function, specified as a compiler.build.Results object.

Name of the Docker image. It must comply with Docker naming rules.

Example: 'hello-world'

Data Types: char | string

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'ExecuteDockerBuild','on'

Path to the build folder where the Docker image is built, specified as a character vector or a string scalar. The path can be relative to the current working directory or absolute.

If no path is specified, the function creates a build folder named ImageNamedocker in the current working directory.

Example: 'DockerContext','/home/mluser/Documents/MATLAB/docker/magicsquaredocker'

Data Types: char | string

Flag to build the Docker image, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • If you set this property to 'on', then the function will build the Docker image.

  • If you set this property to 'off', then the function will populate the DockerContext folder without calling 'docker build'.

Example: 'ExecuteDockerBuild','Off'

Data Types: logical

Name of the Docker image, specified as a character vector or a string scalar. The name must comply with Docker naming rules. Docker repository names must be lowercase. If the main executable or archive file is named using uppercase letters, then the uppercase letters are replaced with lowercase letters in the Docker image name.

Example: 'ImageName','magicsquare'

Data Types: char | string

Output Arguments

collapse all

Microservice Docker image build options, returned as a MicroserviceDockerImageOptions object.

Version History

Introduced in R2022a