Ask Your Question
1

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

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

dparkar gravatar image

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

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

1 Answer

Sort by ยป oldest newest most voted
2

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

gvdhoorn gravatar image

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

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 imagegvdhoorn ( 2018-01-24 03:27:11 -0600 )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 imagedparkar ( 2018-01-26 00:13:17 -0600 )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 imagedparkar ( 2018-01-26 01:02:20 -0600 )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 imagegvdhoorn ( 2018-01-31 03:02:18 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 1,065 times

Last updated: Jan 24 '18