Home > Mobile >  How can one dockerize a Terminal Gui application to run on Linux
How can one dockerize a Terminal Gui application to run on Linux

Time:01-30

I have created a terminal app in C# .NET 6 using Terminal Gui. I have dockerized it but for some reason every time i run the container it keeps exiting with 139, after looking at the logs it initially mentioned that it was missing libncursew.so.5/6 then i added apk add ncurses but after that now I'm getting that same 139 exit code but no additional detail in the logs.

Has anyone dockerized a Terminal.Gui app?

Thanks in advance

CodePudding user response:

From you question I assumed that you are trying to dockerize Terminal.Gui on an alpine based container (you've mentioned an apk package manager).

Here is an example of dockerizing Terminal.Gui template app on an alpine linux image:

  • Create a template terminal gui app:

    dotnet new --install Terminal.Gui.templates
    dotnet new tui -n myproj
    cd myproj
    dotnet run
    
  • Publish it, so we'll be able to use it in a container:

    dotnet publish -c Release -r linux-musl-x64 --self-contained
    
    • -r stands for run runtime, this is important since we'll be publishing our binaries on another OS, just to keep things working. This is a must for alpine linux, otherwise it won't work.
    • --self-contained means that we won't need to install dotnet framework on a machine where app will run
  • Create a dockerfile:

    FROM alpine:latest
    RUN apk add --no-cache  ncurses musl-dev gcc icu bash
    WORKDIR /app
    COPY ./bin/Release/net6.0/linux-musl-x64/publish/ /app
    CMD bash -c /app/DockerizingTui
    
    • ncurses, musl-dev, gcc, icu and bash are requirements of terminal.gui lib, I found it out via trial and error. Probably part of this is an overkill and you won't need to install full packages, just a little subset of libraries that come with those packages.
    • published app copied under /app folder in a container.
  • Build an image:

    docker build -t tuiapp .
    
  • Create and run container:

    docker run --tty --interactive --env TERM tuiapp
    
    • --tty this is a terminal gui app, have to instruct docker to assigne a pseudo tty
    • --interactive otherwise controls won't work
    • --env TERM have to pass TERM variable of a shell that invokes docker run. If your environment doesn't have TERM env variable set (like in windows terminal for example) you can set it explicitly, like this: ```--env TERM=xterm-256color``, tested it on windows terminal as well.

It should work, tested it on a ubuntu wsl, with tmux and without tested it on a windows terminal from cmd.

  • Related