Issues installing Ubuntu packages with Matlab-provided Docker images

I am attempting to do “Matlab in the cloud with Dynare”. I’m not a Dynare expert, but quite comfortable with Linux systems and Docker.

Installing in cloud instances (CodeOcean-provided Matlab and Matlab-provided images) fails. There are two issues, outlined below, and I sketch out possible solutions, but they would need to be implemented by the package maintainers (Sebastien?)


Common to both

In both cases, the base OS is Ubuntu 20.04.

Installation of Matlab is not necessary - each image has Matlab pre-installed. However, the Matlab-provided image requires a login to a Mathworks account to actually run matlab, even when running with a network license (not sure if this matters). The account is prompted when launching matlab, interactively.

In both cases, installation happens via apt-get in the Dockerfile. (see follow-up message for details) Installing dynare DEB package works (version is 4.6.0). It is the dynare-matlab package that fails.

Issue one: non-interactive building fails, because the package interactively prompts for inputs (such as the Matlab location).

Possible solution: pass answers to those questions in via environment variables.

Issue two: when interactively installing (apt-get dynare-matlab), answers are prompted, but installation fails with error message. See next message.

Help would be appreciated, because this would be quite convenient to have working!

Dockerfile (working)

FROM mathworks/matlab:r2021a

ARG DEBIAN_FRONTEND=noninteractive

USER root
RUN apt-get update \
    && apt-get install -y  \
        dynare=4.6.0+dfsg-2 \
    && rm -rf /var/lib/apt/lists/*

USER matlab

Installation (interactive, not working)

docker run -it  -p 8888:8888 --shm-size=512M myself/matlab2021a:2022-11-23 /bin/bash

then, as user matlab:

sudo apt-get update
sudo apt-get install -y dynare-matlab

Prompt 1:

Location of MATLAB installation(s): /opt/matlab/R2021a/

Prompt 2:

Authorized user for MATLAB: 

(left blank)

Prompt 3:

Rename MATLAB's GCC libraries? [yes/no] 

answer: yes

Prompt 1 is repeated:

Setting up matlab-support ( ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/ line 76.)
debconf: falling back to frontend: Readline
MATLAB interface configuration

The MATLAB interface needs to know where MATLAB is installed on this system. This can be specified as a single directory or, in case of multiple MATLAB installations, as a glob expression (any
expression supported by bash, including extended pattern matching operators).

If, for example, the MATLAB executable is installed in /opt/matlab76/bin/matlab, please enter "/opt/matlab76". If there are multiple MATLAB versions installed, you can enter "/opt/matlab*" or a similar
expression. Only matches that really contain a MATLAB executable will be considered. Therefore, a glob expression may match more than just MATLAB installation directories without negative side effects.

Location of MATLAB installation(s): 

with same answer as before.

This leads to failure:

Setting up dynare-matlab (4.6.0+dfsg-2) ...
Building Matlab extensions (logfile at /tmp/dynare-matlab-mexbuild-1669224388.a98qMX7)
configure: error: MATLAB cannot be found
dpkg: error processing package dynare-matlab (--configure):
 installed dynare-matlab package post-installation script subprocess returned error exit status 1

Not sure how to address this. One fix that was tried (no success)

ln -s /usr/local/bin/matlab /usr/local/bin/MATLAB

Another attempt:

  1. First call up matlab. The configuration of the Mathworks login with password is only asked the first time.
  2. Then run sudo dkpg --configure -a

Same error as before.


sudo cat /tmp/dynare-matlab-mexbuild-1669224534.4xLVQdb 

Copyright (C) 2010-2011 Michael Hanke <>

Licensed under GNU General Public License version 3 or later.
This is free software; see the source for copying conditions.  There is NO

Written by Michael Hanke.

Attempt to build Matlab extensions

Package name:        dynare-matlab
Source directory:    /usr/src/matlab/dynare-matlab
MEX dir:             /usr/lib/matlab/site/dynare-matlab
M dir:               /usr/share/matlab/site/m/dynare-matlab
Build user (if any): 
Build command:       cd mex/build/matlab && ./configure --with-matlab=$(dirname $(dirname $(readlink -f `which matlab`))) MATLAB_VERSION=$(echo version | matlab -nodesktop -nodisplay -nosplash 2>/dev/null | sed -En "/ans\ =/!d;n;n;s/^[^0-9]*([0-9]+\.[0-9]+).*$/\1/;p") && make
Install command:     mkdir -p /usr/lib/dynare/mex/matlab && install -m644 /usr/src/matlab/dynare-matlab/mex/matlab/* /usr/lib/dynare/mex/matlab
Clean command:       cd mex/build/matlab && make distclean && rmdir /usr/src/matlab/dynare-matlab/mex/build/matlab/*/.deps && rmdir /usr/src/matlab/dynare-matlab/mex/matlab

Attempt to build Matlab extensions:
cd mex/build/matlab && ./configure --with-matlab=$(dirname $(dirname $(readlink -f `which matlab`))) MATLAB_VERSION=$(echo version | matlab -nodesktop -nodisplay -nosplash 2>/dev/null | sed -En "/ans\ =/!d;n;n;s/^[^0-9]*([0-9]+\.[0-9]+).*$//;p") && make
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for MATLAB prefix... /opt/matlab/R2021a
checking whether to enable MATLAB support... yes
checking for MATLAB version... unknown
checking for MEX-file suffix... mexa64
setting MEX-file suffix to .mexa64
checking for MATLAB machine architecture... glnxa64
checking for a sed that does not truncate output... /usr/bin/sed
checking for options to compile MEX for MATLAB... ok

Hm. That.

I’m installing from source, but ran into problem there.

Most likely it’s because you’re running a too recent MATLAB version compared to the Dynare version (which is quite old). You should either upgrade to Dynare 5.3 or downgrade to MATLAB R2019b.