Running musescore from within a docker container

For a project, I’m wanting to run the excellent musescore from the CLI to bulk convert .mscz files into MusicXML, PDF renders and even instrumental MP3s in bulk. However because the user content is from modern versions of musescore, and the server is very old, I’m having to use docker to run a modernish version of ubuntu that supports version 4 of musescore. Also when running musescore from a CLI it is very painful because it’s unfortunately built to be a GUI application. The following Dockerfile allows us to run it:

FROM ubuntu:22.04

RUN apt update && \
    DEBIAN_FRONTEND=noninteractive apt install -y --no-install-suggests xvfb wget libopengl0 musescore ca-certificates && \   
    wget -O musescore.appimage https://cdn.jsdelivr.net/musescore/v4.4.1/MuseScore-Studio-4.4.1.242490810-x86_64.AppImage && \
    chmod +x musescore.appimage && \
    apt remove -y wget musescore && \
    ./musescore.appimage --appimage-extract && \
    rm musescore.appimage

ENTRYPOINT [ \
        # Hangs with the error in the GUI if there was an issue so force it to stop at some point
        "/usr/bin/timeout", "10", \
        # Fake X server
        "xvfb-run", "-s", "-screen 0 640x480x24 -ac +extension GLX +render -noreset", \
        # Run the actual command
        "squashfs-root/bin/mscore4portable" \
    ]

For some reason the appimage itself doesn’t pass stuff through correctly so we have to extract it and run the app directly from the filesystem. We can then run it like:

docker run --rm -v $PWD:/data -it musescore /data/001.mscz -o /data/out.xml

to convert a file.

Leave a Reply

Your email address will not be published. Required fields are marked *