0

My dev environment is a docker instance running tmux 3.1c, usually from within a Windows Terminal. The launch script creates a new user account with the hostname $USER and matching uid/gid values so that if I modify files from within the environment they are correctly permissioned. It launches a shell for the user using the runuser command.

This works fine for the most part, but if I launch the instance and tmux, and then adjust the size of the window, my tmux instance doesn't adjust. stty size also doesn't update and shows an incorrect value.

This only happens within the docker instance, and if I run tmux on the host itself within Windows Terminal, it's fine. In fact, if I run tmux within a normal docker instance it's fine too, but if I launch as the $USER account using runuser it breaks.

This might seem complicated but it's the smallest reproducible example I could come up with. If I remove the use of runuser and run simply as root the terminal adjusts correctly when running tmux. Conversely, if I do use runuser but don't launch tmux then the output of stty size correctly adjusts as well. So it's something to do with the interaction of docker/runuser/tmux where things are breaking.

Here is the smallest reproducible example I managed to come up with:

docker-compose.yml

version: "3.3"
services:
  test:
    build: .
    stdin_open: true
    tty: true
    hostname: "test"

Dockerfile

FROM python:3.9.10
RUN apt-get update

RUN apt-get install -y less sudo tmux

COPY add_user.sh /tmp/add_user.sh

add_user.sh

#!/bin/bash

USERNAME=$1
GROUPNAME=$1
USERID=$2
GROUPID=$3

addgroup --gid $GROUPID $GROUPNAME
adduser --uid $USERID --gecos "" --disabled-password --gid $GROUPID $USERNAME
chown -R $USERNAME:$GROUP /home/$USERNAME

launch.sh

USERID=$(id -u ${USER})
GROUPID=$(id -g ${USER})

CMD="/tmp/add_user.sh $USER $USERID $GROUPID && runuser -l $USER -c '/bin/bash'"

docker-compose --file $(dirname $0)/docker-compose.yml run --rm test bash -c "$CMD"

Reproduction steps

docker compose build && ./launch.sh

Now open tmux and check the window size:

tmux
stty size

In my case this produces the following:

quant@test:~$ stty size
18 106

Now adjust the size of the window. In my case this scrambles the tmux window, moves the cursor to the wrong part of the screen, and stty size produces the same output as before:

enter image description here

exiting tmux and running stty size produces the correct result:

quant@test:~$ tmux
[exited]
quant@test:~$ stty size
19 69

Any ideas what could be causing this?

System details:

  • Tmux version is 3.1c
  • Windows terminal is 1.13.11431.0
  • Host OS is Windows 10 running a WSL2 instance of Debian Buster

1 Answer 1

0

I'm going to post a workaround that I found. This is barely an answer since I still don't understand why runuser fails, but replacing runuser -l $USER -c '/bin/bash' in launch.sh with sudo -u $USER '/bin/bash' fixes the problem.

So something funky is going on between runuser and tmux/docker but I really don't know what it was...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .