Skip to content

Running Webots in a Docker container

Olivier Michel edited this page Mar 16, 2022 · 1 revision

Depending on the server use case, it may be desirable to run the Webots instance in a Docker container.

  1. Install docker and docker-compose

  2. Allow cyberbotics to use docker: sudo usermod -aG docker $(whoami) (a reboot will be needed to take this into account).

  3. 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
    
  4. 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
    
  5. 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
    
  6. Create the docker image:

    docker build -t webots .
  7. 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
  8. 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:

    1. 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.
    2. 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.
Clone this wiki locally