-
Notifications
You must be signed in to change notification settings - Fork 2
Running Webots in a Docker container
Depending on the server use case, it may be desirable to run the Webots instance in a Docker container.
-
Install docker and docker-compose
-
Allow
cyberbotics
to use docker:sudo usermod -aG docker $(whoami)
(a reboot will be needed to take this into account). -
Install docker-nvidia2:
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update sudo apt-get install -y nvidia-docker2 sudo systemctl restart docker
-
Test that you can start Webots in a docker on the local machine:
xhost +local:root docker run --gpus=all -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw cyberbotics/webots:latest
Note: if you are connected on the local machine using
ssh -X
, you will need to go through the following steps:XAUTH=/tmp/.docker.xauth touch $XAUTH xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - chmod 777 $XAUTH docker run -it -e DISPLAY=$DISPLAY -v $XAUTH:$XAUTH -e XAUTHORITY=$XAUTH --net host -v /tmp/.X11-unix:/tmp/.X11-unix:rw cyberbotics/webots:latest webots --batch /usr/local/webots/projects/languages/python/worlds/example.wbt
-
Build the docker images for the version(s) of Webots you want to support using the following
Dockerfile
:FROM cyberbotics/webots:R2022a-ubuntu20.04 RUN apt update RUN apt install -y python3-pip python-is-python3 firejail
-
Create the docker image:
docker build -t webots .
-
Test the docker image:
docker run --gpus=all -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw webots webots --batch webots/projects/samples/devices/worlds/camera.wbt
-
Deployment A problem with using a docker image of Webots is that the simulation resources (textures, meshes, sounds, etc.) are downloaded each time an instance of the image is started to run Webots with the same world file. There are two solutions to this problem:
- Share a local folder on the host machine and map it as a read-write volume to
/root/.cache/Cyberbotics/Webots
.- advantage: all the resources are properly stored in a common cache.
- disadvantage: since the volume is available as a read/write also for controllers and physics plug-ins, they may mess it up, breaking the server.
- Include the standard Webots resources in the Docker image.
- advantage: users cannot mess it up.
- disadvantage: if an external resource is not included in the Docker image, it will be loaded every time the docker is run. This is however a pretty rare case which can be circumvented by adding the resource locally, e.g., to the project repository.
- Share a local folder on the host machine and map it as a read-write volume to