Docker shell killed in ROS2 when run this command source install/setup.bash

Hi,

When I build the package using 'colcon build’ then using second command 'source install/setup.bash’ before launch my terminal is getting out from the Docker container every single time and I am not able to launch the package inside docker conatiner.

Anyone can help how can i stay built my package (launch) inside the docker shell using
$ colcon build
$ source install/setup.bash

Hi @m23qures,

You probably have the “exit on error” flag set on your terminal.

If you open a blank terminal (outside docker), and tries to open a file that doesn’t exist, the terminal normally is kept open. Example:

ls -lh /wrong-file

However, if you set the “exit on error" flag, then the terminal is closed if the command fails. Example:

set -e   # Enabling EXIT ON ERROR


ls -lh /wrong-file

Now you see that the terminal closes automatically.

I think the same thing is happening to the terminal that you have inside docker. You probably called “set -e” somewhere.

Just try set +x to disable that “exit on error” flag, then call source install/setup.bash again.

If the terminal doesn’t close, then you know for sure that the flag was set.

The terminal understands that any program that ends with an EXIT CODE different from 0 (zero) exited with an error.

You can see the exit code using “$?” .

Example:

ls -lh

echo "Exit code: $?" 

ls -lh /wrong-file

echo "Exit code: $?" 

Please let us know how your tests go after calling set +e.

Hi,
Thanks for the prompt response. But unfortunetly, this solution is not working.

  • I tried setting “set +e” and “set +x” after soucre install/setup.bash but again it getting out from the docker shell!

HI @m23qures,

would you mind showing us the content of start.sh to help us better identify the possible cause for the error?

Sure, below the content od start.sh file

#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source $DIR/robot.env

# install files in config if they are not there
searchpath=${DIR}/configs/
searchpath_len=$((${#searchpath}+1))
for filename in $(find "${searchpath}"); do
    entry=$(echo $filename | cut --bytes=${searchpath_len}-)
    dest=${DIR}/../${entry}
    if [ ! -e ${dest} ]; then
        echo "Installing config file $(basename ${filename}) in $dest"
        cp -R ${filename} ${dest}
    fi
done

if [ -f $DIR/../.ssh/.id_rsa_robohub ]; then
    chmod go-rwx $DIR/../.ssh/id_rsa_robohub
fi

# copy gitconfig from home
if [ ! -f ${DIR}/../.gitconfig ] && [ -f $HOME/.gitconfig ]; then
   cp $HOME/.gitconfig ${DIR}/../
   # install some default git config elements
   git config --file ${DIR}/../.gitconfig alias.lg "log --pretty=oneline --abbrev-commit --graph --decorate --all"
fi

# Variables required for logging as a user with the same id as the user running this script
export LOCAL_USER_NAME=$USER
export LOCAL_USER_ID=`id -u $USER`
export LOCAL_GROUP_ID=`id -g $USER`
export LOCAL_GROUP_NAME=`id -gn $USER`
DOCKER_USER_ARGS="--env LOCAL_USER_NAME --env LOCAL_USER_ID --env LOCAL_GROUP_ID --env LOCAL_GROUP_NAME"

# Variables for forwarding ssh agent into docker container
SSH_AUTH_ARGS=""
if [ ! -z $SSH_AUTH_SOCK ]; then
    DOCKER_SSH_AUTH_ARGS="-v $(dirname $SSH_AUTH_SOCK):$(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK"
fi

# Settings required for having nvidia GPU acceleration inside the docker
DOCKER_X11_ARGS="--env DISPLAY --ipc=host --volume=/tmp/.X11-unix:/tmp/.X11-unix:rw"

which nvidia-docker > /dev/null 2> /dev/null
HAS_NVIDIA_DOCKER=$?
if [ $HAS_NVIDIA_DOCKER -eq 0 ]; then
  DOCKER_COMMAND=nvidia-docker
  DOCKER_GPU_ARGS="$DOCKER_GPU_ARGS --env NVIDIA_VISIBLE_DEVICES=all --env NVIDIA_DRIVER_CAPABILITIES=all"
else
  #echo "Running without nvidia-docker, if you have an NVidia card you may need it"\
  #"to have GPU acceleration"
  DOCKER_COMMAND=docker
fi


xhost + 

#ADDITIONAL_FLAGS="--detach"
ADDITIONAL_FLAGS="--rm --interactive --tty"
ADDITIONAL_FLAGS="$ADDITIONAL_FLAGS --device /dev/dri:/dev/dri --volume=/run/udev:/run/udev"

# forward joystick/spacemouse input device
if [ -e /dev/input/js0 ]; then
    ADDITIONAL_FLAGS="$ADDITIONAL_FLAGS --device /dev/input/js0"
    readlink -f /dev/input/js0 > /dev/null
    if [ 0 == "$?" ]; then
        ADDITIONAL_FLAGS="$ADDITIONAL_FLAGS --device $(readlink -f /dev/input/js0)"
    fi
fi

# forward local cameras
for filename in $(find /dev -name "video*"); do
    ADDITIONAL_FLAGS="${ADDITIONAL_FLAGS} --device ${filename}"
done


if [ -z "${IMAGE_NAME}" ]; then
    IMAGE_NAME=git.uwaterloo.ca:5050/robohub/turtlebot4:latest
    if [ ! -z "${1}" ]; then
        IMAGE_NAME=${1}
    fi
fi
echo Starting container: $IMAGE_NAME

if [ ! -z "${DOCKER_ROBOT_FLAGS}" ]; then
    ADDITIONAL_FLAGS="${ADDITIONAL_FLAGS} ${DOCKER_ROBOT_FLAGS}"
fi

if [ -z "${CONTAINER_NAME}" ]; then
    CONTAINER_NAME=uw_${ROBOTNAME}_${USER}
fi

docker network create ${CONTAINER_NAME} || echo "Network already exists"
echo ${CONTAINER_NAME}
if ! docker container ps | grep -q ${CONTAINER_NAME}; then
    echo "Starting new container with name: ${CONTAINER_NAME}"
    $DOCKER_COMMAND run \
    $DOCKER_USER_ARGS \
    $DOCKER_X11_ARGS \
    $DOCKER_GPU_ARGS \
    $DOCKER_SSH_AUTH_ARGS \
    -v "$DIR/..:/home/${USER}" \
    $ADDITIONAL_FLAGS --user root \
    --name ${CONTAINER_NAME} --workdir /home/$USER \
    --cap-add=SYS_PTRACE \
    --cap-add=SYS_NICE \
    --cap-add=NET_ADMIN \
    --dns=$(cat /run/systemd/resolve/resolv.conf | grep nameserver | sed -s "s/nameserver //" | head -n 1) \
    --device /dev/bus/usb \
    --device /dev/net \
    --network ${CONTAINER_NAME} \
    $IMAGE_NAME
else
    echo "Starting shell in running container"
    docker exec -it --workdir /home/${USER} --user $(whoami) ${CONTAINER_NAME} bash -l -c "stty cols $(tput cols); stty rows $(tput lines); bash"
fi

# vim: set et ts=4 sw=4

Hi @m23qures,

I’ve been analyzing your start.sh script but I couldn’t find any clues.

I executed your script locally, but I don’t have the workspace and config files that you have, so, my container locally doesn’t start in the same way as yours.

If it was a script that we (from The Construct) provided, it would be easier for us to identify the error and solve it.

Things you can test:

  1. If you try any other commands, they fail? What if you try “ls -lh”?
  2. If the problem is only with the source command, then you probably have an error in your compiled workspace. I would recommend you do a backup first, then remove the build install log folders, and rebuild work workspace.

Hi @ralves

  1. other commands i.e “ls -lh” is working
  2. I deleted the ws and created new one witgout any package but when run “source install/setup.bash” same results.

I am attaching a code script, if you “./file_name” then after installation a folder name “robohub” will be created on your home dir and inside you there’s a folder name “turtlebo4” and all content including “start.sh” is present. Can you try running at your end to check the problem please!

Here is the command:

mkdir /home/$USER/robohub && cd /home/$USER/robohub && git clone https://git.uwaterloo.ca/robohub/turtlebot4.git

Hi @m23qures,

I’ve just tested the same commands, and for me, it worked nicely. So, it must be something on your computer.

Here we have a screenshot that I just took:

Hi @ralves
Wow, this is great man. Thank you. It might be problem with the docker installation. Any recommendations where to install docker?
Cheers,
Maaz

Hi @m23qures,

I’m temporarily using Ubuntu 20.04.6 LTS.

In the link below you can see the supported platforms for Docker:

Maybe you can try uninstalling Docker and installing it again, to see if the problem goes away.

Or maybe your computer doesn’t have enough RAM or CPU, I don’t know.

I really have no idea why this happens to you, especially knowing that it works nicely for me.

When you have it working, please let us know how you solved it so that we can better help if anyone comes later with the same problem.

Hi @ralves
I idid the reinstallations and tried several ways but ot able to reolve the error. Can you help or recommend other way around to reolve the error please?

  • I installed the docker from this link [Install Using Apt Repository] then did these post installation steps.

  • Ubuntu version: 22.04.4 (Ubuntu).

  • Docker Version: Docker version 26.0.0, build 2ae903e

  • Yes, everything is upto date. Did the reinstallation of docker couple of times as well.

Findings: I did the same docker installation from the above links on another laptop . It has window installed VM for ubuntu, the source install.setup.bash is working without error ala not “kiiled” but its super slow and crashes thats why using the below laptop for work.

Appendix:
Moreover, the laptop system i have is lenovo T16 G2, i7-1355u, 32gb ram, 1tb ssd with irisx graphics

Hi @m23qures,

I’m out of ideas as to why this error happens specifically with your Ubuntu 22.

Actually, the reason why I use Ubuntu 20.04.6 LTS. is because when I tried Ubuntu 22, about two years ago, I had problems with a Ubuntu plugin that I like, which shows that load in my computer, like CPU, RAM, Network, etc. With Ubuntu 22, this plugin/extension always crashed my PC. That is why I’m with Ubuntu 20. I’m eager to see Ubuntu 24 available, which should be available in April 2024, to have a more updated Ubuntu distro.

So, the only thing that comes to mind now is that you try Ubuntu 20, but this would require you to do a backup of your files, and it is not guaranteed to work. I think it can solve the problem, but I can’t guarantee because I don’t know exactly what happens there, since it works on my PC, and it works on your Ubuntu VM.

Or you could wait until April and install Ubuntu 24. Ubuntu 24.04 LTS, codenamed Noble Numbat, is scheduled for release on April 25, 2024. If that is just too much time for waiting, trying Ubuntu 20 could be an alternative.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.