From 972079faf2d87937905c94ff01c766a0c0b2b2cd Mon Sep 17 00:00:00 2001 From: Rick Staa Date: Fri, 19 Jan 2024 10:13:58 +0100 Subject: [PATCH] feat: add docker container (#379) This pull request adds a docker container that can be used to run the SLC package. This was done to improve the reproducibility of results. --- .devcontainer/devcontainer.json | 26 ++++++++++++++++++++ Dockerfile | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..f0fe12ea0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,26 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile +{ + "name": "Existing Dockerfile", + "build": { + "context": "..", + "dockerfile": "../Dockerfile" + }, + "runArgs": [ + "-e", + "DISPLAY=${localEnv:DISPLAY}", + "-v", + "/tmp/.X11-unix:/tmp/.X11-unix:ro" + ], + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python" + ] + }, + "settings": { + "python.pythonpath": "/opt/conda/envs/han2020/bin/python" + } + }, + "postCreateCommand": "echo 'If you need to run GUI applications inside this Docker container, remember to execute `xhost +local:docker` on your host machine to enable X11 forwarding. You can remove it again with `xhost -local:docker` when you are done.'" +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..b5183af86 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# Use the official Miniconda3 base image +FROM continuumio/miniconda3:latest + +# Set environment variables for Conda +ENV CONDA_HOME="/opt/conda" +ENV PATH="$CONDA_HOME/bin:$PATH" + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + libopenmpi-dev \ + && rm -rf /var/lib/apt/lists/* + +# Create a Conda environment with Python 3.10 +RUN conda create -n slc python=3.10 + +# Activate the Conda environment +SHELL ["conda", "run", "-n", "slc", "/bin/bash", "-c"] + +# Copy the repo code into the Docker image +COPY . /stable-learning-control + +# Clone stable-gym package +RUN git clone https://github.com/rickstaa/stable-gym.git + +# Set the working directory +WORKDIR /stable-learning-control + +# Install mpi4py using Conda +# NOTE: Done since the pip version of mpi4py does not to seem to work in a Conda environment. +RUN conda install mpi4py + +# Install slc package +# RUN pip install -e . +RUN pip install -e .[mujoco] + +# Install the stable-gym package +RUN pip install -e ../stable-gym + +# Add Conda activation to .bashrc (optional) +RUN echo "source activate slc" >> /root/.bashrc + +# Start the experiments +ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "slc", "python", "-m", "stable_learning_control.run"]