How to install a virtual Donkey Car on your PC using docker

Jonathan Tse
Robocar Store
Published in
4 min readNov 11, 2020

--

Background

Setting up the Donkey Car software to run on your PC could be a challenging task, depending on your level of expertise in Python. It also depends on which platform you are using. Windows users tends to encounter more problems. If you are a teacher, you probably don’t want your students to spend 1 hour figuring out how to properly setup Conda or python without having any success running the Donkey Car software. How can we make the experience smoother?

One day, when I was preparing a talk to a group of teachers, I was wondering … how can I let them try Donkey Car without even installing the software? What if they could just download the mobile app and then connect to the simulator and race together? Is that possible?

It turns out both problems could be solved by containerizing the Donkey Car software. And better yet, I can run multiple virtual donkey car container in a single host and connect to the same simulator to do a head to head race.

How it works

  • The Docker host uses a script to create 3 docker container, namely donkeycar1, 2 and 3. At the same time, the script will create a mycarX folder for each of these virtual Donkey Car, where X represent the number of the car.
  • Each of these docker container is installed with the Donkey Car software, donkey car console (which is used to communicate with the app). In the example above, they will listen to port 8000–8002 to allow the mobile app to discover them. The virtual donkey car is configured in a simulator mode by setting DONKEY_GYM to True in myconfig.py.
  • User will be asked to install the Donkey Car Controller on their phone. By using the app, they will discover these 3 virtual Donkey Cars. They will be instructed which car they will be using.
  • Now we also need to start the Donkey Car simulator running the same way we use it on the host.
  • When the user start driving using the app, the virtual donkey car will connect to the simulator and show up.
  • User could drive, train and test on the app.

Installation

Install Docker

  • Docker
  • Docker-compose

You need to install Docker on the Docker host. Follow these instruction to install Docker on Windows 10 Home, Mac and Linux. Note that if you are using a relatively outdated Windows 10 Home as the Docker host, it would take quite a long time to install Docker as it requires the Win 10 version 1903 and up.

Checkout the repository

git clone https://github.com/sctse999/donkeycar-docker

How to use it

After you have checked out the repo, you can start the docker container using one of the way below.

Single Player

If you just want to use the Docker image for solo purpose (e.g. development or testing the v4 branch), you can run the start.sh / start.bat in the repo. I use it frequently to test the mobile app. Note that by default this script will build the docker image from ground up. It will take some time for the 1st time.

Multi-player

Use this when you want to create multiple Donkey Car container at the same time. Run python multi_player.py. The script will prompt you the number of racer you would like to create. As mentioned above, it will take some time to run for the first time as it is pulling the docker image from docker hub.

No matter you chose single or multiple players, you can check whether your docker container is running by using the command docker ps.

Start the simulator

Start the simulator just as the way you would start it. Let the simulator stay in the menu screen.

Launch the mobile app

When you launch the mobile app, the mobile app will start to discover Donkey Car(no matter physical or virtual) on the same network. You should be seeing something like this.

Stop the virtual car

When you finish using the virtual Donkey Car, use stop.sh or stop.bat to stop all the containers. Note that the stop.bat will kill all running docker containers in the system. If you are running other docker containers, please be extra careful NOT to use this command.

Change the racer name

If you are using single player mode, change myconfig.py in the mycar folder.

If you are using multi player mode, change myconfig.py under each of the mycarX folder.

Troubleshooting

Check the log

You can check the log of the docker container by

docker logs -f donkeycar1

Shell access to the virtual donkey car

docker exec -it donkeycar1 bash

Activate the virtual environment inside the donkey car and start driving manually. If the app cannot start the car, you can check the output of the following command.

source /env/bin/activate
cd ~/mycar
python manage.py drive

--

--

Jonathan Tse
Robocar Store

Love Self-driving technology and machine learning. Community leader in DIYRobocar Hong Kong.