0
$\begingroup$

Rosanswers logo

I am using ROS in a Docker container. I followed this tutorial.

Now I am going through the other tutorials and working through them inside the container as "root".

The problem : after sourcing ros_entrypoint.sh, in case I type in any "bad" command (e.g. trying to cd into a directory that doesn't exits) the container stops and I am back to my regular bash shell.

The container status shows : Exited (1)

This is how I get back into the container every time :

docker container start CONTAINERID 
docker attach zen_aryabhata (I have also tried : docker exec -it zen_aryabhata bash) 
source ./ros_entrypoint.sh

Here's the behavior :

root@CONTAINERID:/# cd blah
bash: cd: blah: No such file or directory
root@CONTAINERID:/# source ./ros_entrypoint.sh 
root@CONTAINERID:/# cd blah
bash: cd: blah: No such file or directory
dparkar@MYMACHINE:~$

Originally posted by dparkar on ROS Answers with karma: 11 on 2018-01-24

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

tl;dr: ros_entrypoint.sh is not a file to source.


It's a wrapper shell script that sources the correct setup.bash for you and then invokes whatever you passed it in that new environment (from osrf/docker_images/ros/indigo/ubuntu/trusty/ros-core/ros_entrypoint.sh):

#!/bin/bash
set -e

# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"
exec "$@"

This file is then configured as the ENTRYPOINT of your Docker container, and will be run / prefixed everytime you spin up a container.

In a way, when you run the following:

$ docker run -it --rm ros:indigo rostopic echo /some_topic

it does this (inside the container):

/entrypoint.sh rostopic echo /some_topic

Which then first sources /opt/ros/indigo/setup.bash (as this is an Indigo image) and then runs rostopic echo /some_topic in that same environment.

According to bash-hackers.org/commands/builtin/exec, exec replaces the current shell and will terminate if it cannot execute what you ask it to.

If you source the file, it could be that you actually end up in the exec line, which after asking it to cd to a non-existing directory terminates and as the Docker session now has no active programs any more, it also exits, leaving you at the bash prompt of your host's terminal.


Originally posted by gvdhoorn with karma: 86574 on 2018-01-24

This answer was ACCEPTED on the original site

Post score: 4


Original comments

Comment by gvdhoorn on 2018-01-24:
See #q241349 for a related question.

Comment by dparkar on 2018-01-26:
The reason why I was explicitly doing that is because some commands do not work. e.g. "rostopic", "roscd" and "rosls" are not recognized but "rostopic" and "roscore" are recognized.

Comment by dparkar on 2018-01-26:
Okay, sourcing just the setup.bash seems to solve it: "source "/opt/ros/$ROS_DISTRO/setup.bash". But I don't get why I have to source it again if ros_entrypoint.sh is internally calling setup.bash anyway.

Comment by gvdhoorn on 2018-01-31:
I'm not sure why you had to do that. It would seem to be a different question - which should be posted as a new one.

$\endgroup$
0
$\begingroup$

Rosanswers logo

Clearly, the official ros-docker-docs are wrong and are promoting the above technique which leads to mentioned "bug".

@dparkar's answer is based on the contents of ros_entrypoint.sh, where he sources manually with

source "/opt/ros/$ROS_DISTRO/setup.bash

This is obviously tedious to do each time one logs into the bash of a container. I simplified it with the following script source_me.sh:

#!/bin/bash
# setup ros environment
source "/opt/ros/$ROS_DISTRO/setup.bash"
source "/root/catkin_ws/devel/setup.bash"

where in the last line I also source other relevant projects. I call it with

source source_me.sh

each time im logging into the bash.


Originally posted by Sebastian1234 with karma: 11 on 2021-01-13

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.