Docker is a tool that enables us to run an application in an isolated environment called a container. Containers are lightweight and contain all dependencies required to run a particular application which frees us from the hassle of manual installation of dependencies. Containers can be easily be shared as they are independent of the host operating system. Shared containers work exactly the same on every machine with Docker installed.
-
Install Docker from here
-
Check if Docker properly install by running in Docker Terminal:
docker run hello-world
-
To pull Turtlesim Docker Image run:
docker pull yagneshde/ros_turtlesim:latest
-
To run the Docker Image run:
docker images docker run -it <IMAGE ID>
-
To create catkin workspace follow Step 6 of Running Turtlesim ROS Node on Docker (Manually)
-
Install Docker from here
-
Check if Docker properly install by running in Docker Terminal:
docker run hello-world
-
Now run:
docker run --net=host --env="DISPLAY" -v "${PWD}:/myvol" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --name roslocal -it ros:melodic /bin/bash
This step will take some time so be patient and ensure internet connectivity.
Option | Description |
---|---|
--net=host |
Connects the container to host network |
--env="DISPLAY" |
Passes environment variable which enables us to use GUI |
-v "${PWD}:/myvol" |
Mounts the current working directory of host machine at the time of starting the container. To access current working directory in the container navigate to myvol. Note: Make sure the name of the folder is unique, i.e. myvol should not clash with other folders in the container's root directory. |
--volume |
Allows us to mount a volume from local storage from the host machine |
--name roslocal |
Allows us to give roslocal as the name of the container. If not specified Docker gives a random name to it. Check using docker ps -a |
-it |
Allows us to use interactive mode |
ros:melodic |
Name of the Docker Image. See more here |
/bin/bash |
To get bash shell in the terminal |
- Note:
-
To stop the Docker container use:
docker ps docker stop <CONTAINER ID>
-
To start Docker container use:
docker ps -a docker start <CONTAINER ID> docker exec -it <CONTAINER NAME> bash
-
-
Installing Turtlesim:
First update the container using
apt-get update
To install Turtlesim run:
sudo apt-get install ros-melodic-turtlesim
-
To open another terminal for the same instance of
roslocal
container, run:docker exec -it roslocal bash
-
Creating catkin workspace:
cd myvol mkdir -p ~/catkin_ws/src cd catkin_ws catkin_make
Creating ROS package named
ros_basics
cd src catkin_create_pkg ros_basics
-
To source setup.bash open a new terminal of same instance of the container from step 5.
sudo apt update sudo apt install vim -y cd vim .bashrc
Now navigate to the bottom of the file and add the following:
source /opt/ros/melodic/setup.bash source /myvol/catkin_ws/devel/setup.bash
Press ESC and type
:wq
to save and exit vim. -
To start ROS Master run:
roscore
To start turtlesim node run:
rosrun turtlesim turtlesim_node
To start turtlesim tele-operation run:
rosrun turtlesim turtle_teleop_key
-
Clone the package into the created catkin workspace,
catkin_ws
cd /myvol/catkin_ws/src git clone https://github.com/yagdev99/TurtlesimDocker cd .. catkin_make
-
Starting ROS Master:
roscore
-
To run
talker.py
open a new terminal of the same instance of the container and run:rosrun TurtlesimDocker talker.py
-
To run
listener.py
open a new terminal of the same instance of the container and run:rosrun TurtlesimDocker listener.py
You should now see messages being puslished by talker.py
and displayed by listener.py
- To learn more about Docker refer to Docker Docs
- Docker vs. Virtual Machines: https://geekflare.com/docker-vs-virtual-machine/
- Writing DockerFile: https://docs.docker.com/engine/reference/builder/