ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

docker container : Exited (1) on "bad" command

asked 2018-01-23 23:34:52 -0500

dparkar gravatar image

updated 2018-01-23 23:53:29 -0500

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:~$
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
4

answered 2018-01-24 03:26:54 -0500

gvdhoorn gravatar image

updated 2018-01-24 03:58:44 -0500

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.

edit flag offensive delete link more

Comments

See #q241349 for a related question.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-24 03:27:11 -0500 )edit

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.

dparkar gravatar image dparkar  ( 2018-01-26 00:13:17 -0500 )edit

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.

dparkar gravatar image dparkar  ( 2018-01-26 01:02:20 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-31 03:02:18 -0500 )edit
0

answered 2021-04-09 23:29:01 -0500

brac24 gravatar image

I was having the same issue.

But it actually worked for me when using melodic. I was originally running a foxy version container but thought I was running melodic. I changed to running a melodic version container and roscore was not found.

Until I ran source ros_entrypoint.sh. Then roscore magically worked.

I don't know if my issue was fixed because I restarted a new container but it worked for me using the melodic container and not the foxy version which I believe or ros2.

Just wanted to give my experience in case it helps anyone.

edit flag offensive delete link more
1

answered 2021-01-13 03:51:50 -0500

Sebastian1234 gravatar image

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-01-23 23:34:52 -0500

Seen: 2,455 times

Last updated: Jan 24 '18