osrf / rocker

A tool to run docker containers with overlays and convenient options for things like GUIs etc.
Apache License 2.0
530 stars 68 forks source link

Terminal behaves strange with --x11 option #152

Open AndreasAZiegler opened 3 years ago

AndreasAZiegler commented 3 years ago

When I start rocker with the --x11 option, I observe the following unexpected behavior:

tfoote commented 2 years ago

I can't reproduce any of these issues testing rocker --x11 ubuntu The X11 plugin only adds some extra runtime mounting devices. Are you running an X based terminal on top?

Please provide the full set of commands that you're running to produce this problem. And possibly a recording of the behavior. Also any information about your keyboard setup.

AndreasAZiegler commented 2 years ago

Thanks @tfoote for investigating this issue.

My problem comes from the fact that TERM is not set. The problem is now, that if I set TERM with

rocker --nvidia --x11 --user --home --privileged --env TERM=xterm --volume /dev/bus/usb:/dev/bus/usb --volume
/data:/data -- prophesee-ros

this results in

docker run --rm -it -e TERM=xterm -v /home/ziegler:/home/ziegler   --gpus all --privileged -v /dev/bus/usb:/dev/bus/usb -v /data:/data  -e DISPLAY -e TERM   -e QT_X11_NO_MITSHM=1   -e XAUTHORITY=/tmp/.docker4k4p15ro.xauth -v /tmp/.docker4k4p15ro.xauth:/tmp/.docker4k4p15ro.xauth   -v /tmp/.X11-unix:/tmp/.X11-unix   -v /etc/localtime:/etc/localtime:ro  5ba210881fbd

and therefore, TERM is not set as it is overwritten. My workaround is to set TERM manually with export TERM=xterm, but this is obviously annoying. Is there a way to set TERM without having it overwritten?

tfoote commented 2 years ago

Currently there's not. When injecting the argument here: https://github.com/osrf/rocker/blob/acbbff59d6aef6a9654eabc0ff7e3f823936d6e3/src/rocker/nvidia_extension.py#L49 it would need to be able to check for other environment variables set and only set it if unset.

There's a possibilty that you could use parameter substitutions: https://unix.stackexchange.com/a/122848/83370

However looking back at it, the x11 is passing through your host TERM settings. So the trivial solution is to prepend TERM=xterm to your command like this. Or set your TERM variable in your environment.

TERM=xterm rocker --nvidia --x11 --user --home --privileged --volume /dev/bus/usb:/dev/bus/usb --volume /data:/data -- prophesee-ros

Example adding TERM at the beginning passing through. ``` $ TERM=xterm rocker --x11 -- ubuntu bash Extension volume doesn't support default arguments. Please extend it. Active extensions ['x11'] Writing dockerfile to /tmp/tmpsf0rjxn9/Dockerfile vvvvvv # Preamble from extension [x11] FROM ubuntu USER root # Snippet from extension [x11] ^^^^^^ Building docker file with arguments: {'path': '/tmp/tmpsf0rjxn9', 'rm': True, 'nocache': False, 'pull': False} building > Step 1/2 : FROM ubuntu building > ---> 1318b700e415 building > Step 2/2 : USER root building > ---> Using cache building > ---> 5da8b17d3e78 building > Successfully built 5da8b17d3e78 Executing command: docker run --rm -it -e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 -e XAUTHORITY=/tmp/.dockersuqlq__h.xauth -v /tmp/.dockersuqlq__h.xauth:/tmp/.dockersuqlq__h.xauth -v /tmp/.X11-unix:/tmp/.X11-unix -v /etc/localtime:/etc/localtime:ro 5da8b17d3e78 bash root@79d0b45173a2:/# env | grep TERM TERM=xterm root@79d0b45173a2:/# exit tfoote@snowman5:~ Last: [0] (13s Seconds) $ TERM=foo rocker --x11 -- ubuntu bash Extension volume doesn't support default arguments. Please extend it. Active extensions ['x11'] Writing dockerfile to /tmp/tmpeshhsjed/Dockerfile vvvvvv # Preamble from extension [x11] FROM ubuntu USER root # Snippet from extension [x11] ^^^^^^ Building docker file with arguments: {'path': '/tmp/tmpeshhsjed', 'rm': True, 'nocache': False, 'pull': False} building > Step 1/2 : FROM ubuntu building > ---> 1318b700e415 building > Step 2/2 : USER root building > ---> Using cache building > ---> 5da8b17d3e78 building > Successfully built 5da8b17d3e78 Executing command: docker run --rm -it -e DISPLAY -e TERM -e QT_X11_NO_MITSHM=1 -e XAUTHORITY=/tmp/.dockeryq2fx1e6.xauth -v /tmp/.dockeryq2fx1e6.xauth:/tmp/.dockeryq2fx1e6.xauth -v /tmp/.X11-unix:/tmp/.X11-unix -v /etc/localtime:/etc/localtime:ro 5da8b17d3e78 bash root@a1cf74fa2317:/# root@a1cf74fa2317:/# env | grep TERM TERM=foo ```

Also https://github.com/osrf/rocker/pull/130 might help with this issue too, but putting the user envs later in the evaluation logic.