This repository contains required files to run ROS noetic (or any other version of ROS) inside a docker container (with GUI support as well). User "docker" is created inside the container without password and with sudo privileges. Default shell for container is bash, but this can be changed by changing the dockerfile: bash_ros.Dockerfile
line to dockerfile: zsh_ros.Dockerfile
in docker-compose.yml
file.
GUI applications (such as RViz and Gazebo) should work on Windows 10/11 with WSL2, but for native Windows installation (running Docker inside Windows without WSL), you most likely need to run X Server in order for the GUI applications to work (e.g. VcXsrv).
Only Docker is needed to run the container. If you use older versions of docker, you will have to install Docker Compose as well (as it doesn't come with the Docker package by default). To install Docker Compose, follow the instructions here.
-
Clone this repository with
git clone https://github.com/Silviis/ros-docker.git
-
Then place your ROS workspace folder inside the cloned repository manually. The workspace should be named
catkin_ws
(can be edited indocker-compose.yml
). -
(OPTIONAL) If you have your workspace folder in version control, the easiest way to utilize this repository is to fork this repository and then add your catkin workspace as a submodule to that repository. To do so, first clone your fork, then remove the
catkin_ws
folder from the repository with:cd ros-docker
Then add your workspace as a submodule with:
git submodule add https://github.com/yourusername/your_catkin_ws.git catkin_ws
Note that if you are running older versions of Docker, you might need to use docker-compose
instead of docker compose
.
-
First make the repository folder your current working directory (in host system):
cd ros-docker
-
To pull, build and run the container use:
docker compose up -d
This will pull the base image from Docker Hub, make some changes to it (see
Dockerfile
) and run it in detached mode. -
To attach a shell to the running container run the following command:
docker compose exec ros bash
This will attach a bash shell to the running container. Replace
bash
withzsh
if you are usingzsh
as your shell. -
Now you should be able to use the ROS tools inside the container. For example:
rostopic list
-
To build the workspace inside the container, first enter the workspace folder (inside the container environment) with:
cd /home/docker/catkin_ws
and build the workspace with
catkin build # Or catkin_make if it is preferred
-
Then access your ros packages inside the container, first source the workspace with:
source /home/docker/catkin_ws/devel/setup.bash
or
source /home/docker/catkin_ws/devel/setup.zsh
if you are using
zsh
as your shell. -
Now you should be able to run your ROS packages inside the container as you would normally do. For example:
rosrun yourpkg yournode
-
To exit the container, simply type
exit
in the terminal (or pressctrl + d
). To shut down the container use:docker compose down
This will stop and remove the container. Notice that this command will remove all the changes made to the container (installed packages etc.) excluding the changes made to the workspace folder (and its subfolders) as it is mounted to the host system. You can add more mounted directories (even multiple workspaces) to the container in
docker-compose.yml
file if needed. -
The environment variables (ROS_IP & ROS_MASTER_URI) in
.env
file should be edited according to your needs. The default values point to localhost. You can also set these variables inside the container environment if you prefer (e.g. by runningexport ROS_IP=your_ip
inside the container).