|
1 | 1 | # Building matlab-proxy for use in a Docker Container |
2 | 2 |
|
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. |
4 | 10 |
|
5 | 11 | ## Build image |
6 | 12 | ```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 |
8 | 42 | ``` |
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 |
10 | 69 | ```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 |
12 | 72 | ``` |
| 73 | +For a complete list of environment variables that can be passed, see [Advanced-Usage.md](../Advanced-Usage.md) |
0 commit comments