Matlab microservice in Docker Compose

7 views (last 30 days)
bluhub
bluhub on 17 Apr 2024
Answered: Harsh on 30 Aug 2024
I created a microservice in MATLAB according to following how-to and it works as expected: https://de.mathworks.com/help/compiler_sdk/mps_dev_test/create-a-microservice-docker-image.html
I built a web-app, which shall use that ML-container and retrieves data from it. When I run both containers independently, communication works as expected.
I now had the plan to put them into a docker-compose and start-up my application via compose. This is the compose-file, that I currently use:
services:
web:
image: web_app:latest
ports:
- "5000:5000"
environment:
- MLSL_URI=http://mlsl:9910
mlsl:
image: mlsl_server:latest
ports:
- "9900:9910"
container_name: mlsl
I now face following issue:
  • web-container cannot access the ML-container's necessary service via the internal port - I receive HTTP404
  • I use following endpoint for that http://mlsl:9910/functionarchive/convertData
I tried following things:
  • I checked the external endpoint of the container via http://mlsl:9900/api/health and received HTTP200
  • the service of the ML-container is still accessible and I receive data via the external port
  • via http://mlsl:9900/functionarchive/convertData
  • I checked the internal endpoint of the internal network of the container via http://mlsl:9910/api/health and receive a HTTP403, indicating permission issues
So I am quite stuck. Is there any way to access the services inside the docker network or is it just possible to access the public docker port of the ML-container? Do I need to change the container build settings in ML/SL? I used the settings as mentioned in the how-to of ML/SL.

Answers (1)

Harsh
Harsh on 30 Aug 2024
Hi,
From what I can gather, you are trying to run 2 MATLAB docker images simultaneously using docker-compose and call 1 image from another.
Here's a guide on how MATLAB Docker images can interact when deployed with Docker Compose:
  • In this example, two functions have been created: thisAdds and makeCalls:
function c = thisadds(a, b)
c = a + b;
end
When specifying the connection, instead of using "localhost," the local IP address is used. This IP can be found using various methods, such as executing ifconfig (requires net-tools) on the WSL.
  • These functions can be compiled using the compiler.build.productionServerArchive command.
(For thisadds.m)
thisAddsObj = compiler.build.productionServerArchive('thisadds.m',...
'FunctionSignatures','thisaddsFunctionSignatures.json',...
'ArchiveName','thisaddsarchive','Verbose','on')
(For makecall.m)
makecallObj = compiler.build.productionServerArchive('makecall.m',...
'FunctionSignatures','makecallFunctionSignatures.json',...
'ArchiveName','makecallarchive','Verbose','on')
Additionally, a function signature has been created for makeCalls. More information about function signatures can be found at the following link:
  • The Docker images are created using the compiler.package.microserviceDockerImage function.
(To create thisadds docker image)
compiler.package.microserviceDockerImage(thisAddsObj,'ImageName','thisadds')
(To create makecall docker image)
compiler.package.microserviceDockerImage(makecallObj,'ImageName','makecall')
  • Next, access the WSL to verify the creation of Docker images. The names of the images should be listed:
docker images
  • Create a docker-compose.yml file to configure the setup.
Note: To change the endpoint from 9910, modifications in the MATLAB image are necessary; simply changing the port mapping from 5000:5000 will not suffice without adjustments.
  • Run Docker Compose to start the services:
docker-compose up
  • Finally, call the makeCalls Docker image to test the setup:
Voila, it works!!

Categories

Find more on Containers in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!