Howto build VNC and Browser mode into matlab docker container?

21 views (last 30 days)
I cannot use the prebuilt matlab docker container as I need to provide my username to our license server. Is there any way to force the pre-built container to use a specific user name for license checkout?
When I rebuild a container using the provided Dockerfile from matlab-dockerfile to incorporate my username I am unable to use -vnc or -browser. Which packages do I have to include to get these features included? I could not find this documented anywhere. Is the Dockerfile that was used for building the prebuilt container available somewhere?
Thanks for your support.

Answers (1)

Prabhakar
Prabhakar on 21 Mar 2025
Edited: Prabhakar on 21 Mar 2025
The Dockerfile presented below can be used to build a new container based on the mathworks/matlab container to add the desired username while making sure that the flags ( -browser , -vnc ) supported by the existing entrypoint are honored.
# Dockerfile
ARG CONTAINER_USERNAME="yourusername"
FROM mathworks/matlab:R2024b
ARG CONTAINER_USERNAME
USER root
# Add "CONTAINER_USERNAME" user and grant sudo permission.
RUN adduser --shell /bin/bash --disabled-password --gecos "" $CONTAINER_USERNAME \
&& echo "${CONTAINER_USERNAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$CONTAINER_USERNAME \
&& chmod 0440 /etc/sudoers.d/$CONTAINER_USERNAME \
&& cp -r /home/matlab/Documents /home/${CONTAINER_USERNAME}
# Set user and work directory.
USER $CONTAINER_USERNAME
WORKDIR /home/$CONTAINER_USERNAME
# Install MATLAB-PROXY for -browser capabilities
RUN pipx install matlab-proxy
ENV PATH=/home/${CONTAINER_USERNAME}/.local/bin:$PATH
By default it would create a new user called "yourusername" which you could also supply another value using the --build-arg while building the container as shown below:
docker build -t MyMATLABContainer --build-arg CONTAINER_USERNAME=NewUser -f Dockerfile .
Verify that the new user was installed:
docker run -it --rm --entrypoint /bin/bash MyMATLABContainer -c whoami
NewUser
Finally,
  1. The link to the Github Repository that builds the Official Container is listed at the bottom of the README page on DockerHub.
  2. The MATLAB Proxy repository has an example Dockerfile which shows how to add browser mode into another base container. Note this Dockerfile resets the entrypoint to always start the container in the browser mode.
  3. Please track this issue on Github to be notified when any new developments are made to make this process simpler.
Hope this helps.

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!