Fonts in interactive ubuntu terminal

Hey there,
i’m trying to run ubuntu on my mac via docker. The goal is to create a docker image with my dotfiles installed, so that i can run the image and get a clean interactive ubuntu terminal with preinstalled dotfiles (proper zsh, tmux, neovim etc). But right now i’m struggeling with fonts. My tmux statusline and my zsh prompt uses some special fonts from the MesloLGS NF.ttf. Usually i just install this font manually and tell my terminal emulator (alacritty, kitty or iterm) to use it by adjusting it’s config. But in docker it’s different: the terminal emulator is not there since bash or zsh are executed directly by docker (e.g. after starting a docker container with: docker container run -it my_image). So who is in charge setting the fonts for the terminal?

I configured my Dockerfile in a way, that it downloads all my cusom fonts, moves them to the /usr/local/share/fonts and ~/.fonts directory for system-wide and per user installation. Then i run fc-cache -f -v to update my font cache. I can check with fc-list that all my fonts are installed correctly. But when i run tmux, the statusbar looks terrible since the wrong fontset is used. Tmux for instance has no ability to use a different font than the parent terminal. But as of my understanding, there is no parent terminal. It’s just docker that spawns that shell process directly. Any ideas how to tell docker to use custom fonts?

NOTE: I know i can get GUI applications running inside docker with this [magic](: Running GUI’s with Docker on Mac OS X | by Nils De Moor | Containerizers) and then install a graphical terminal emulator like kitty but this seems like an overkill to me

I don’t think you need those fonts inside the container when your graphical interface is not inside. I just tried it. Installed ohmyzsh in a container and switched to the “agnoster” theme which also requires some fonts which are already on my mac host. It works fine from iTerm.

You are right. If I run just zsh with my statusline Plugin (powerline10k) it pick’s up the fonts of my host system (in my case macOS) and displays them right. But if i run zsh inside tmux, special characters are shown wrong. Why should tmux change the font set? i tested it with vanilla tmux (no configurations).

Ok I tried that too :slight_smile: It works. When I run tmux inside the container it starts a new bash shell not zsh. I had to start a zsh shell inside tmux and then execute source ~/.zshrc. I also created a Dockerfile for you with the agnoster theme. Feel free to change it to your needs

FROM ubuntu:20.04

SHELL ["bash", "-c"]

RUN apt-get update \
 && apt-get install --no-install-recommends -y \
      zsh \
      git \
      curl \
      ca-certificates \
 && set -eu -o pipefail \
 && curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh | zsh -

RUN apt-get install --no-install-recommends -y tmux \
 && cat /root/.zshrc | sed 's/ZSH_THEME=".*"/ZSH_THEME="agnoster"/' > /root/.zshrc_tmp \
 && mv /root/.zshrc_tmp /root/.zshrc \
 && echo "set-option -g default-shell /bin/zsh" > /root/.tmux.conf

ENV LANG=C.UTF-8

ENTRYPOINT ["zsh"]
1 Like

Ok i still don’t get what was the problem with my Dockerfile. It was very similar to yours but i was having this kind of problems. Nevertheless i could get it running now. Your minimal example helped a lot. Thank you very much! Regards Jonas

I guess the UTF-8 character set and the default shell setting for tmux helped too. I could not activate ohmyzsh until I set the LANG variable.