This repository contains the necessary files to create docker containers for experimenting with Gymnasium and Stable-Baselines3.
The containers can be executed in Linux and Windows (either directly of using WSL2).
| Feature | Linux/WSL2 | Windows |
|---|---|---|
| GPU CUDA support | ✔️ | ✔️ |
| Interactive visualization | ✔️ | |
| Video recording | ✔️ | ✔️ |
| Classic control environments | ✔️ | ✔️ |
| Box2D environments | ✔️ | ✔️ |
| ToyText environments | ✔️ | ✔️ |
| MuJoCo environments | ✔️ | |
| Atari environments | ✔️ | ✔️ |
- Docker installed (Docker engine preferred in Linux systems)
- (for GPU support) NVIDIA CUDA drivers and NVIDIA Container Toolkit installed
The following instructions are for easily creating and using containers with docker compose:
-
Select a working directory for your project in your host computer (e.g.
rl-scripts) and move there. This directory will be mapped inside the container in the path/home/rl/my_scripts. -
Download in that directory the
compose.yamlfile from github. -
Execute one of the below options, depending on your system, to create the container (default name is
rltrain). It is recommended to usesudopreceding the docker commands in Linux.
Note
It may take some minutes to download the image the first time.
-
Starting the Linux/WSL2 CPU-only container:
sudo docker compose up linux-cpu -d -
Starting the Linux/WSL2 GPU-enabled container:
sudo docker compose up linux-gpu -d -
Starting the Windows CPU-only container:
docker compose up windows-cpu -d -
Starting the Windows GPU-enabled container:
docker compose up windows-gpu -d
Warning
Do not forget the final -d
-
Open a terminal session on the container
rltrain(multiple terminal sessions maybe opened on the same container for starting tensorboard or parallel trainings):docker exec -it rltrain /bin/bash -
For stopping the container after working with it:
docker stop rltrain -
To start the container again, just execute the previous
docker compose upcommand, or:docker start rltrain
In a different terminal session on the container, type:
tensorboard --logdir logs --bind_all
The container provides the following directory structure:
── /home/rl/
├── examples
│ ├── check_cuda.py
│ ├── test_gymnasium.py
│ └── test_sb3.py
└── my_scripts
my_scripts: this is where the working directory of the host is mapped. Your python scripts and experiments should be here.examples: some example scripts are provided here, to check basic functionalitycheck_cuda.py: checks that CUDA is properly configured and displays the number of GPUs available.test_gymnasium.py: launches a Gymnasium environment passed as parameter (--helpfor detailed parameters information).test_sb3.py: launches a Stable-Baselines3 training with a Gymnasium environment (--helpfor detailed parameters information).
Example: launch a Gymnasium test in interactive mode
python test_gymnasium.py --env LunarLander-v2 -n 100000
Example: launch a Gymnasium test and record the episodes videos (a videos directory will be created in the working directory).
python test_gymnasium.py --env Ant-v4 -n 100000 -r
Warning
Note: as Ant-v4 is based on MuJoCo, this environment is not supported in the Windows-based container.
Example: launch a SB3 training interactively and log progress in tensorboard (a logs directory will be created in the working directory):
python test_sb3.py --env LunarLander-v2 --algo ppo -n 200000 -t
Note
For videos and tensoboard logs, the videos and logs directories are created in the working directory, therefore for the above examples, in order to be able to accessvideos and logs from the host computer, those directories should be generated under the my_scripts (which is mapped on the host). That can be easily done by invoking the example scripts from the my_scripts directory:
rl@foobar:/home/rl/my_scripts$ python ../examples/test_sb3.py --env LunarLander-v2 --algo ppo -n 200000 -tdocker build -f rl-base.Dockerfile -t inakivazquez/rl-base:latest .
This example is for CUDA + MuJoCo support in Linux/WSL2 using network mode host:
docker pull inakivazquez/rl-base
docker container create --name rltrain --privileged --network host -it --gpus all -v .:/home/rl/my_scripts -e DISPLAY=$DISPLAY -e SDL_VIDEODRIVER=x11 -v /tmp/.X11-unix:/tmp/.X11-unix inakivazquez/rl-base
docker start rltrain
docker exec -it rltrain /bin/bash
Follow the instructions at the Ubuntu tutorial for WSL2, basically:
- Install WSL for Windows 10 / 11
- Install Ubuntu over WSL:
wsl --install Ubuntu
Follow the official instructions at NVIDIA website.