This guide outlines the steps to run your first ROS node through a Docker container. The Docker container is pre-configured with Ubuntu 20.04 and ROS Noetic.
Based on: Docker container with pre-installed Ubuntu20.04 and ROS Noetic
- Base Image: Ubuntu 20.04
- ROS Distribution: Noetic
- Docker and docker compose installed on your system. You can check if Docker is installed by running
docker --version
in your terminal.
Clone the repository containing the Dockerfile:
git clone [email protected]:Suyannesara/ROS-noetic-docker.git
cd ROS-noetic-docker
The Dockerfile provided in this project defines an image with ROS Noetic installed.
**Modify your bashrc file to source ros1 i
Modify the Dockerfile to use your system user:
Then, build the image by running the following command in your terminal:
ARG USER=your_os_user
your_os_user
with your actual system username. Also, make sure you are inside this project's root folder to run the next commands.
Run the container based on the defined image using the following commands:
sudo docker compose up -d
It is normal if it takes long to build for the first time!
Once you've done the steps till now, your docker container is running on your machine in the background, so that you are able to open multiple instances of the container with the command:
sudo docker exec -it ros-noetic-container /bin/bash
This will open your container work around.
In a terminal OUTSIDE the container one, run:
xhost +local:docker
Then, gazebo will be able to launch any ways you need. You can check by pasting the comand above INSIDE container terminal:
gazebo
The comands above are necessary in order to source ros1 itens. Whenever you use roscore, you are going to need to execute these lines first. In your terminal, paste:
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
echo "source /opt/ros/noetic/setup.sh" >> ~/.bashrc
source ~/.bashrc
Inside a container terminal instance, run the following command to start roscore
:
roscore
In a terminal OUTSIDE the container one, run the command above if have not done it yet:
xhost +local:docker
In another docker container terminal instance (that you can open with the command in section 4.1), run the following command to start the Turtlesim node:
rosrun turtlesim turtlesim_node
(Do not close the window with roscore
running; they both should be opened)
This should open a window displaying the Turtlesim environment like this:
In another docker container instance terminal tab, run the following command to control the turtle using keyboard inputs:
rosrun turtlesim turtle_teleop_key
Just to clarify, at the end of the process, you should have something like this, with 3 terminal tabs open, 2 of them taking care of running two different nodes, and the other running the roscore environment, necessary for running the nodes.
You can exit each docker terminal instance by typing "exit"
🎉 All done: Now, you can use the arrow keys on your keyboard to control the movement of the turtle in the Turtlesim environment.