YoumustperformthesestepsonaLinuxplatform.Beforestarting,youmustinstallthefollowingontheclientplatform
DockerGitIntroductionThefollowingstepsguideyouthroughtheprocessofcreatingaDockercontainerimagethatcontainsaLinuxenvironmentwithaMATLABinstallation.UsethecontainerimageasascalableandreproduciblemethodtodeployMATLABinavarietyofsituationsincludingcloudsandclusters.
Step1.ClonethisRepositoryClonethisrepositorytoyourLinuxclientusing
gitclonehttps://github.com/mathworks-ref-arch/matlab-dockerfile.git
Insidetheclonedrepository,createasubdirectorynamedmatlab-install
Step2.ChooseMATLABInstallationMethodToinstallMATLABintothecontainerimage,chooseaMATLABinstallationmethod.YoucanuseMATLABinstallationfilesoraMATLABISOimage.
MATLABInstallationFilesToobtaintheinstallationfiles,youmustbeanadministratorforthelicenselinkedwithyourMathWorksaccount.
FromtheMathWorksDownloadspage,selectthedesiredversionofMATLAB.DownloadtheInstallerforLinux.FollowthestepsatDownloadProductsWithoutInstallation.Specifythelocationofthematlab-installsubdirectoryoftheclonedrepositoryasthepathtothedownloadfolder.SelecttheinstallationfilesfortheLinux(64-bit)versionofMATLAB.Selecttheproductsyouwanttoinstallinthecontainerimage.Confirmyourselectionsandcompletethedownload.MATLABISOFromtheMathWorksDownloadspage,selectthedesiredversionofMATLAB.UndertheRelatedLinksheading,clickthelinktogettheISOimageforthechosenMATLABversion.DownloadtheISOimagefortheLinux.ExtracttheISOintothematlab-installsubdirectoryoftheclonedrepository.Step3.ObtaintheLicenseFileandFileInstallationKeyLogintoyourMathWorksaccount.Selectthelicenseyouwishtousewiththecontainer.SelecttheInstallandActivatetab.Selectthelink“ActivatetoRetrieveLicenseFile”.ClickthedownloadlinkundertheGetLicenseFileheading.SelecttheappropriateMATLABversionandclickContinue.Attheprompt“Isthesoftwareinstalled?”select“No”andclickContinue.CopytheFileInstallationKeyintoasafelocation.Step4.DefineInstallationParametersMakeacopyofthefileinstaller_input.txtinthematlab-installfolder.Movethecopyuponedirectorylevel,intotherootdirectoryoftheclonedrepository.Renamethefiletomatlab_installer_input.txt.Openmatlab_installer_input.txtinatexteditorandeditthefollowingsections:fileInstallationKeyPasteyourFileInstallationKeyanduncommenttheline.agreeToLicenseSetthevaluetoyesanduncommenttheline.Specifyproductstoinstall.Uncommentthelineproduct.MATLABtoinstallMATLAB.Uncommentthecorrespondinglineforeachadditionalproductyouwanttoinstall.Ifyouarenotlicensedtouseaproduct,uncommentingthelinedoesnotinstalltheproductinthecontainer.YourFileinstallationKeyidentifiestheproductsyoucaninstall.(Optional)SpecifyrequireddependenciesintheDockerfile.EdittheDockerfileanduncommentthecorrespondinglineforeachdependencyyouwanttoadd.Formoreinformation,seeOptionalDependencies.Step5.BuildImageUsethedockerbuildcommandtobuildtheimage,using.tospecifythisfolder.Runthecommandfromtherootdirectoryoftheclonedrepository.Useacommandoftheform:
dockerbuild-tmatlab:r2020a--build-argLICENSE_SERVER=27000@MyServerName.Note:TheLICENSE_SERVERbuildargumentisNOTusedduringthebuildbutbysupplyingithereduringbuilditgetsincorporatedintothecontainersothatMATLABinthecontainerknowshowtoacquirealicensewhenthecontainerisrun
TobuildapreviousversionofMATLAB,forexampleDockerfile.R2019b,useacommandoftheform
dockerbuild-fDockerfile.R2019b-tmatlab:r2019b--build-argMATLAB_RELEASE=R2019b--build-argLICENSE_SERVER=27000@MyServerName.Youmustsupplyatagfortheimageusingthe-toption,forexample,matlab:r2020a.Thetagnamestherepositoryforlateruseanddeployment.Specifythelocationofthenetworklicencemanagerusing--build-argLICENSE_SERVER=27000@MyServerName.Replace27000@MyServerNamewiththeportandlocationofyourlicensemanager.Alternatively,youcanusealicense.datornetwork.licfiletoprovidethelocationofthelicensemanager.Formoreinformation,seeUseaLicenseFiletoBuildImage.
FortheR2019bDockerfileyoumustalsospecifytheMATLABreleaseusing--build-argMATLAB_RELEASE=R20xxx,whereR20xxxreferstoaMATLABreleaseyouaretryingtobuild.
Step6.RunContainerUsethedockerruncommandtorunthecontainer.Useacommandoftheform:
dockerrun-it--rmmatlab:r2020a-itoptionrunsthecontainerinteractively.--rmoptionautomaticallyremovesthecontaineronexit.AnyextraargumentsafterthecontainertagarepasseddirectlyascommandlineargumentstotheMATLABprocessinsidethecontainer.Forexample,thefollowingcommandprintshelloworldinMATLABandthenexits.
dockerrun-it--rmmatlab:r2020a-r"disp('helloworld');exit"OptionalDependenciesForsomeworkflowsandtoolboxes,youmustspecifydependencies.Youmustdothisifyouwanttodoanyofthefollowingtasks.
InstallextendedlocalizationsupportforMATLABPlaymediafilesfromMATLABRunanetworklicensemanagerinsidethecontainerGeneratecodefromSimulinkUsemexfunctionswithgcc,g++,orgfortranUsetheMATLABEngineAPIforCandFortranUsethePolyspace32-bittcccompilerEdittheDockerfileanduncommenttherelevantlinestoinstallthedependencies.
UseaLicenseFiletoBuildImageIfyouhavealicense.datfilefromyourlicenseadministrator,youcanusethisfiletoprovidethelocationofthelicensemanagerforthecontainerimage.
Openthelicense.datfile.CopytheSERVERlineintoanewtextfile.Beneathit,addUSE_SERVER.Thefileshouldnowlooksomethinglikethis:SERVERServer10123abcd012312345USE_SERVERSavethenewtextfileasnetwork.licintherootdirectoryoftheclonedrepository.OpentheDockerfile,andcommentthelineENVMLM_LICENSE_FILEUncommentthelineADDnetwork.lic/usr/local/MATLAB/$MATLAB_RELEASE/licenses/Runthedockerbuildcommandwithoutthe--build-argLICENSE_SERVER=27000@MyServerNameoption.Useacommandoftheformdockerbuild-tmatlab:r2020a.Formoreinformationaboutlicensefiles,seeWhatarethedifferencesbetweenthelicense.lic,license.dat,network.lic,andlicense_info.xmllicensefiles?
评论