2

I need to work with a graphic application which runs in a docker container on a remote machine (running Ubuntu 16.04) which I access via PuTTY from my local Windows machine with Xming running.

I managed to get as far as connecting to the remote host (via PuTTY X11 options...) and running the container (adding .Xauthority to profile and mapping the container display to my display) in a way that I can run xterm one time but not a second time. It appears the application I need to use requires multiple windows to open, which thus doesn't work.

I use the following script to open the docker container on the remote host

#!/bin/bash

if [ $# -ne 1 ]; then
    echo "Usage: $0 container"
    exit 1
fi

nvidia-smi > /dev/null 2>&1
if [ $? -ne 0 ]; then
    echo "##########################################"
    echo ""
    echo "Nvidia Display driver not installed"
    echo "You will not be able to run the CUDA container"
    echo ""
    echo "##########################################"
    VAR_DRIVER="TRUE"
fi

VAR_CONTAINER=$1
VAR_ARCH=$(uname -i | sed 's/_/-/g')
VAR_NVLIB=$(ldconfig -p | grep libnvcuvid.so | grep -m 1 ${VAR_ARCH} | cut -d "=" -f2 | sed 's/>//g')
VAR_NVPATH=$(dirname ${VAR_NVLIB})
VAR_DOCKER_VOL="-v /dev/bus/usb:/dev/bus/usb -v /home/${USER}/.qnx/license:/root/.qnx/license -v ${PWD}/display/socket:/tmp/.X11-unix -v ${PWD}/display/Xauthority:/root/.Xauthority"

#if [ -z ${VAR_DRIVER} ]; then
 #  VAR_DOCKER_VOL=${VAR_DOCKER_VOL}" -v "${VAR_NVPATH}":/usr/lib/nvidia"
#fi

CONTAINER_DISPLAY="0"
CONTAINER_HOSTNAME="docker_host"

mkdir -p display/socket
touch display/Xauthority

DISPLAY_NUMBER=$(echo $DISPLAY | cut -d. -f1 | cut -d: -f2)

AUTH_COOKIE=$(xauth list | grep "^$(hostname)/unix:${DISPLAY_NUMBER} " | awk '{print $3}')
xauth -f display/Xauthority add ${CONTAINER_HOSTNAME}/unix:${CONTAINER_DISPLAY} MIT-MAGIC-COOKIE-1 ${AUTH_COOKIE}

socat TCP4:localhost:60${DISPLAY_NUMBER} UNIX-LISTEN:display/socket/X${CONTAINER_DISPLAY} &

echo "Connecting docker display "${CONTAINER_HOSTNAME}":"${CONTAINER_DISPLAY}" to local display "$(hostname)":"${DISPLAY_NUMBER}
echo "Moving local Xauthority Cookie "${AUTH_COOKIE}" in "${PWD}"/display/Xauthority to /root/.Xauthority in docker container"

docker run -it --rm  -e DISPLAY=:${CONTAINER_DISPLAY} \
       ${VAR_DOCKER_VOL} \
       --hostname ${CONTAINER_HOSTNAME} \
       --shm-size 2g \
       --runtime=nvidia \
       -e NVIDIA_VISIBLE_DEVICES=all \
       -e NVIDIA_DRIVER_CAPABILITIES='compute,graphics,utility,video' \
       -e NVIDIA_REQUIRE_CUDA='cuda>=10.0 brand=tesla,driver>=384,driver<385 brand=tesla,driver>=410,driver<411' \
       ${VAR_CONTAINER} \
       /bin/bash
rm -r display

I roughly followed the steps in Running a graphical app in a Docker container, on a remote server.

The error I get when trying to open a second xterm from within the docker is

xterm: Xt error: Can't open display: :0
  • What's your DISPLAY value? The error is showing a double colon, which doesn't seem right. – roaima Jan 22 at 12:14
  • It's :0 from within the docker container. I'm sorry i must have omitted a blank there. I'll fix it. – moritzatconti Jan 22 at 12:43
  • Are you trying to run the entire last script from your tutorial? If so, it's bound to fail as it sets up everything new. Just repeat the last docker command (ensuring the variables are all correctly initialised). – roaima Jan 22 at 14:09
  • I'm doing things slightly different. I have a script to run the container which I adapted according to the last step from the tutorial. After I exit the container it also will delete everything set up beforehand. The problem though is that when trying to run e.g. xterm (or any other graphic app) two times from within the docker it will fail. Sorry If I wasn't clear about that above. – moritzatconti Jan 28 at 7:54
  • Can you add the relevant lines of code to your question? Otherwise we're all just guessing at what you might, or might not, have done. – roaima Jan 28 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.