mathworks-ref-arch / matlab-dockerfile

Create a docker container that contains a MATLAB install
Other
337 stars 96 forks source link

Matlab with VNC from compose #123

Open arunoruto opened 2 hours ago

arunoruto commented 2 hours ago

I was trying to start a matlab container using docker compose and it was working for the browser version:

services:
  matlab:
    image: mathworks/matlab:r2024b
    container_name: matlab
    restart: unless-stopped
    command: -browser
    shm_size: 512M
    environment:
      MLM_LICENSE_FILE: /network.lic
    volumes:
      - ./network.lic:/network.lic
    ports:
      - 8888:8888 # web browser connection

But when I try running a VNC session, it just keeps restarting with no obvious error logs! My VNC compose file:

services:
  matlab:
    image: mathworks/matlab:r2024b
    container_name: matlab
    restart: unless-stopped
    init: true
    command: -vnc
    shm_size: 512M
    environment:
      MLM_LICENSE_FILE: /network.lic
    volumes:
      - ./network.lic:/network.lic
    ports:
      - 5901:5901 # vnc
      - 6080:6080 # web browser connection

And the logs:

matlab  | [WARN  tini (7)] Tini is not running as PID 1 and isn't registered as a child subreaper.
matlab  | Zombie processes will not be re-parented to Tini, so zombie reaping won't work.
matlab  | To fix the problem, use the -s option or set the environment variable TINI_SUBREAPER to register Tini as a child subreaper, or run Tini as PID 1.
matlab  | ----------------------------------------------------
matlab  | Welcome to the MATLAB Container
matlab  |
matlab  | This container includes commercial software products of The MathWorks,
matlab  | Inc. ("MathWorks Programs") and related materials. MathWorks Programs are
matlab  | licensed under the MathWorks Software License Agreement, available in the
matlab  | MATLAB installation in this container. Related materials in this
matlab  | container are licensed under separate licenses which can be found in
matlab  | their respective folders.
matlab  |
matlab  | Use the -help flag to learn more about the usage of this container:
matlab  |
matlab  |     docker run mathworks/matlab:R2024b -help
matlab  |
matlab  | To be able to access the container via web browser or VNC, make sure you have exposed port 6080 and 5901, respectively.
matlab  | To get started, either
matlab  |
matlab  |     1. Point a browser to port 6080 of the docker host machine running
matlab  |        this container
matlab  |
matlab  |         http://hostname:6080
matlab  |
matlab  |     2. Use a VNC client to connect to display 1 of the docker host
matlab  |        machine
matlab  |
matlab  |         hostname:1
matlab  |
matlab  | The default password to access the container desktop is
matlab  |
matlab  |     matlab
matlab  |
matlab  | If you require assistance or have a request for additional features or capabilities, please contact MathWorks Technical Support: https://www.mathworks.com/support/contact_us.html

Note, I inserted the init: true, since all the docker run commands have --init flag.

epaganon commented 2 hours ago

Hi @arunoruto ,

Thank you for your message. When running in -vnc (or -shell) mode, the mathworks/matlab Docker container starts a bash shell process, which immediately stops (hence causing the Docker container to stop) if stdin is not open.

To fix the issue you can add the stdin_open: true field to the compose file that you are using. For example:

services:
  matlab:
    image: mathworks/matlab:r2024b
    container_name: matlab
    restart: unless-stopped
    init: true
    stdin_open: true
    command: -vnc
    shm_size: 512M
    environment:
      MLM_LICENSE_FILE: /network.lic
    volumes:
      - ./network.lic:/network.lic
    ports:
      - 5901:5901 # vnc
      - 6080:6080 # web browser connection

Also, the init: true flag is not required in this case.

For more documentation regarding the mathworks/matlab Docker images, please refer to the mathworks-ref-arch/container-images repository and our page on DockerHub.