Skip to content

Commit 6b2d96d

Browse files
diningPhilosopher64Prabhakar Kumar
authored andcommitted
Added Dockerfile and Dockerfile.upgrade.matlab-proxy for installing/upgrading matlab-proxy in docker images
1 parent 5adfeba commit 6b2d96d

File tree

4 files changed

+103
-12
lines changed

4 files changed

+103
-12
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ The following options are available in the status panel (some options are only a
112112
| Help | Open a help pop-up for a detailed description of the options.|
113113

114114
## Examples
115-
* For usage in a Docker container, see this [Dockerfile](./examples/Dockerfile) and its [README](./examples/README.md).
115+
* For installing/usage in a Docker container, see this [Dockerfile](./examples/Dockerfile) and its [README](./examples/README.md).
116+
* For upgrading **matlab-proxy** in an existing Docker image, see this [Dockerfile.upgrade.matlab-proxy](./examples/Dockerfile.upgrade.matlab-proxy) and its [README](./examples/README.md#upgrading-matlab-proxy-package-in-a-docker-image).*
116117
* For usage in a Jupyter environment, see [jupyter-matlab-proxy](https://github.com/mathworks/jupyter-matlab-proxy).
117118

118119
## Limitations

examples/Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
# Copyright 2021 The MathWorks, Inc.
2-
# Enables access to the MATLAB Desktop from a web browser
1+
# Copyright 2021-2022 The MathWorks, Inc.
2+
# This Dockerfile showcases how to add matlab-proxy into an existing container image with MATLAB installed.
33

4-
# Based on the publicly available MATLAB image
5-
FROM mathworks/matlab:r2021b
4+
# matlab-proxy enables access to the MATLAB Desktop from a web browser
5+
6+
# Sample build command:
7+
# docker build --build-arg IMAGE_WITH_MATLAB=my_custom_image_with_matlab \
8+
# -f Dockerfile -t my_custom_image_with_matlab_proxy .
9+
10+
# Sample run command:
11+
# docker run --rm -it -p 8888:8888 --shm-shared=512M my_custom_image_with_matlab_proxy
12+
13+
ARG IMAGE_WITH_MATLAB=mathworks/matlab:r2021b
14+
15+
FROM ${IMAGE_WITH_MATLAB}
616

717
USER root
818

9-
# The container already has python3 (v3.8.5) installed
1019
# Install dependencies for matlab-proxy
1120
RUN DEBIAN_FRONTEND=noninteractive && \
1221
apt-get update && apt-get install --no-install-recommends -y \
@@ -17,12 +26,12 @@ RUN DEBIAN_FRONTEND=noninteractive && \
1726
&& apt-get clean \
1827
&& rm -rf /var/lib/apt/lists/*
1928

20-
RUN python -m pip install matlab-proxy
29+
RUN python3 -m pip install matlab-proxy
2130

2231
# Set environment variables used by integration
2332
# MATLAB should then become accessible on http://localhost:8888/matlab/index.html
2433
ENV MWI_APP_PORT=8888
2534
ENV MWI_BASE_URL="/matlab"
2635

2736
USER matlab
28-
ENTRYPOINT ["matlab-proxy-app"]
37+
ENTRYPOINT ["matlab-proxy-app"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2021-2022 The MathWorks, Inc.
2+
# This Dockerfile showcases how to upgrade the matlab-proxy python package
3+
# in an existing container image which has both MATLAB and matlab-proxy installed
4+
5+
# Sample build command:
6+
# docker build --build-arg IMAGE_WITH_MATLAB_PROXY=my_custom_image_with_matlab_proxy \
7+
# -f Dockerfile.upgrade.matlab-proxy -t my_custom_image_with_matlab_proxy .
8+
9+
# Sample run command:
10+
# docker run --rm -it -p 8888:8888 --shm-shared=512M my_custom_image_with_matlab_proxy
11+
12+
ARG IMAGE_WITH_MATLAB_PROXY=mathworks/matlab:r2022a
13+
14+
FROM ${IMAGE_WITH_MATLAB_PROXY}
15+
16+
USER root
17+
18+
RUN python3 -m pip install --upgrade matlab-proxy
19+
20+
USER matlab

examples/README.md

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,73 @@
11
# Building matlab-proxy for use in a Docker Container
22

3-
Builds a docker image based on `mathworks/matlab` with the **matlab-proxy** integrated.
3+
[Dockerfile](./Dockerfile) adds **matlab-proxy** package to an existing docker image with MATLAB
4+
5+
Supply the name of your custom image with the docker build arg `IMAGE_WITH_MATLAB`. The default value for this build argument is `mathworks/matlab:r2021b`
6+
7+
**NOTE:** Releases of MATLAB docker images starting from `r2022a` will have **matlab-proxy** integrated by default.
8+
9+
This [Dockerfile](./Dockerfile) can be used as a reference for integrating **matlab-proxy** into your custom images or older MATLAB docker images.
410

511
## Build image
612
```bash
7-
docker build -t <image_name> .
13+
docker build --build-arg IMAGE_WITH_MATLAB=my_custom_image_with_matlab_installed \
14+
-f Dockerfile -t my_custom_image_with_matlab_proxy .
15+
```
16+
## Upgrading matlab-proxy package in a docker image
17+
18+
To keep your docker images updated with the latest release of **matlab-proxy** package, you can either:
19+
* Update using a Dockerfile
20+
* Update using `docker commit` command
21+
22+
**NOTE:** Updating the package using a Dockerfile is recommended as it helps in keeping track of the changes made to docker images.
23+
### Approach 1: Using a Dockerfile
24+
`Dockerfile.upgrade.matlab-proxy` showcases how to upgrade an existing installation of **matlab-proxy** package in a docker image.
25+
26+
27+
```bash
28+
docker build --build-arg IMAGE_WITH_MATLAB_PROXY=my_custom_image_with_matlab_proxy \
29+
-f Dockerfile.upgrade.matlab-proxy -t my_custom_image_with_matlab_proxy .
30+
```
31+
32+
### Approach 2: Using `docker commit` command
33+
Launch your container with `--entrypoint /bin/bash` flag
34+
```bash
35+
$ docker run --rm -it --shm-size=512M --entrypoint /bin/bash my_custom_image_with_matlab_proxy:latest
36+
```
37+
38+
Once in the container, change to root user and upgrade the package
39+
```bash
40+
root@6624c4893071:/home/matlab/Documents/MATLAB: sudo su
41+
root@6624c4893071:/home/matlab/Documents/MATLAB: python3 -m pip install --upgrade matlab-proxy
842
```
9-
## Run image
43+
44+
In a new terminal, grab the running container's ID and use the `docker ps` command
45+
```bash
46+
$ docker ps
47+
48+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
49+
6624c4893071 my_custom_image_with_matlab_proxy:latest "/bin/run.sh -shell" 2 minutes ago Up 2 minutes 5901/tcp, 6080/tcp, 8888/tcp laughing_buck
50+
51+
```
52+
In this case, the container ID is `6624c4893071`. Now commit:
53+
```bash
54+
$ docker commit 6624c4893071 my_custom_image_with_matlab_proxy:latest
55+
```
56+
57+
Stop the running container by exiting the shell
58+
```bash
59+
root@6624c4893071::/home/matlab/Documents/MATLAB: exit
60+
matlab@6624c4893071::/home/matlab/Documents/MATLAB: exit
61+
```
62+
63+
## Run the docker container
64+
```bash
65+
docker run -it -p 8888:8888 --shm-shared=512M my_custom_image_with_matlab_proxy:latest
66+
```
67+
68+
For modifying the behaviour of **matlab-proxy**, you can pass environment variables at run time
1069
```bash
11-
docker run -it -p 8888:8888 -t <image_name>
70+
docker run -it -p 8888:8888 -e MLM_LICENSE_FILE="port@hostname" \
71+
--shm-shared=512M my_custom_image_with_matlab_proxy:latest
1272
```
73+
For a complete list of environment variables that can be passed, see [Advanced-Usage.md](../Advanced-Usage.md)

0 commit comments

Comments
 (0)