ROS Docker Setup
Welcome to the Setup Guide for ROS in Docker.
Install Docker
- Create an account on DockerHub
- Follow instructions here to install docker for your Operating System.
Commands Specific to the Watch One, Do One, Teach One Project
One Time Setup
-
Download the Dockerfile located here
-
Navigate to the location where the Dockerfile is saved on your local machine and build the docker using:
sudo docker build -t ros:melodic-desktop-full . -
Test if the docker was built using:
sudo docker images
If the docker was built, the output of this command would look like this -
Obtain the hostname for your system by running:
hostnamectl. ( Hostname can belocalhosttoo) -
Pull the wodoto repository in your local machine if you have not done so already.
-
Spin up a container with the wodoto repository and the sound drivers mounted using the command (Replace
path-to-repositoryandhostnameappropriately):
sudo docker run -it -v ~/.ssh:/root/.ssh -v /dev/snd:/dev/snd --privileged -v <path-to-wodoto-repository>:/root/catkin_ws --network host --env ROS_MASTER_URI=http://<hostname>:11311 --name ros_sound ros:melodic-desktop-full -
Add the following lines to your
~/.bash_profilefile on your local machine replacingpath-to-repositoryandhostnameappropriately. Then source it by running:
source ~/.bash_profile -
Install
pipinside the container by following these instructions. -
Install
viminside the container by following these instructions.
Commands to Start and Test the ROS Docker for the First Time
-
Run the ROS Docker Container created in the previous step by:
sudo docker start ros
docker exec -it ros bash
After running this, we would have entered inside the container, and the prompt will change toroot@<hostname>:/# -
Inside the container source the
setup.shfile by running:
source /opt/ros/melodic/setup.sh -
Check if the
catkin_wsis present inside therootdirectory inside the container. -
The code files should be present inside
root/catkin_ws/and the ROS packages should be present insideroot/catkin_ws/src -
Run
catkin_makeinsideroot/catkin_ws. Aftercatkin_make, check ifbuildanddeveldirectories are created inside thecatkin_ws. Then run:
source devel/setup.bash -
Run the following series of commands to test if we have a running ROS installation and can publish on a topic from within the container.
roscore &
:
rostopic pub -r 1 /test std_msgs/String "test" &
:
These commands mean that we first runroscorein the background, and publish atestmessage on the/testtopic and send that process to the background. -
In order to check if the message was published on the topic run:
rostopic list
The topic/testshould appear on the list. -
To verify if the
testmessage is being published on the/testtopic run:
rostopic echo /test
Instructions for using the same container every time and running code
-
List all the available containers using the command (The first 3 characters of the container ID or the name of the container listed in the last column can be used as the
container_name):
docker ps -
If there is a container found, it means that there is a container available and it is running. In order to enter that particular container use the command:
docker exec -it ros bash -
If there is no container found after running
docker ps, rundocker ps -a. If there is a container found, it means that the container exists but is not running. In order to enter into the container run:
docker start ros
docker exec -it ros bash
The prompt will change toroot@<hostname>:/#once we are inside the container. -
Once inside the container, source the
setup.bashfile using:
source /opt/ros/melodic/setup.bashand inside thecatkin_wsrunsource devel/setup.bash. -
In order to run ROS nodes, first run
roscore &and send it to the background by running:. To spin up the required node, use the appropriaterosrunorroslaunchcommand as we do on the robot.
Shortcuts for Working with the Docker
Some aliases have been added on the .bash_profile file, to make working with this particular docker easier. To refer to what each alias does, see here
They are described here:
build_ros_docker- build the ROS docker (one-time)run_docker- run the docker with the code mounted to create a container (one-time)list_images- list docker images (one-time)list_container- list running containerslist_all_container- list all running as well as stopped containersexec_docker- execute a running container
General ROS Docker Commands
One Time Setup
-
Pull the ROS docker image by running (one time setup):
docker pull ros -
In your local machine clone the repository using the command:
git clone <repository https: path> -
Spin up a container with the git repository mounted using the command:
docker run -v <path_to_repository_in_your_local_machine>:/code/ -it ros
Instructions for using the same container every time
-
Inside the container run
roscore -
On a new terminal, list all the available containers using the command (The first 3 characters of the container ID or the name of the container listed in the last column can be used as the
container_name):
docker ps -
If there is a container found, it means that there is a container available and it is running. In order to enter that particular container use the command:
docker exec -it <container_name> bash -
If there is no container found after running
docker ps, rundocker ps -a. If there is a container found, it means that the container exists but is not running. In order to enter into the container run:
docker start <container_name>
docker exec -it <container_name> bashThis will start an additional bash session in the same container. -
Once inside the container, source the
setup.bashfile using:
source /opt/ros/melodic/setup.bashand inside thecatkin_wsrunsource devel/setup.bash. -
To test if the instance is connected to the same
ros-masterrun:
rostopic list
To edit this document make changes here