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

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, 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 ./

Here's the behavior :

root@CONTAINERID:/# cd blah
bash: cd: blah: No such file or directory
root@CONTAINERID:/# source ./ 
root@CONTAINERID:/# cd blah
bash: cd: blah: No such file or directory
edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

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

gvdhoorn gravatar image

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

tl;dr: 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/

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):

/ 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, 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


See #q241349 for a related question.

gvdhoorn gravatar image gvdhoorn  ( 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 image dparkar  ( 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 is internally calling setup.bash anyway.

dparkar gravatar image dparkar  ( 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 image gvdhoorn  ( 2018-01-31 03:02:18 -0600 )edit

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

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, 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

# 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


each time im logging into the bash.

edit flag offensive delete link more

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

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 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

Question Tools

1 follower


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

Seen: 2,424 times

Last updated: Jan 24 '18