Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(pu): add Dockerfile and its usage instructions #95

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This Dockerfile describes the process of creating a Docker image that includes
# the necessary environment to run the LightZero library.

# The Docker image is based on Ubuntu 20.04, and it installs Python 3.8 and other
# necessary dependencies. It then clones the LightZero library from its GitHub
# repository and installs it in an editable mode.

# Before building the Docker image, create a new empty directory, move this Dockerfile into it,
# and navigate into this directory. This is to avoid sending unnecessary files to the Docker daemon
# during the build. Then you can then build the Docker image using the following command in your terminal:
# docker build -t ubuntu-py38-lz .

# To run a container from the image in interactive mode with a Bash shell, you can use:
# docker run -it --rm ubuntu-py38-lz /bin/bash

# Once you're inside the container, you can run the example Python script with:
# python ./LightZero/zoo/classic_control/cartpole/config/cartpole_muzero_config.py

# Note: The working directory inside the Docker image is /opendilab, so you don't need
# to change your current directory before running the Python script.


# Start from Ubuntu 20.04
FROM ubuntu:20.04

# Set the working directory in the Docker image
WORKDIR /opendilab

# Install Python 3.8 and other dependencies
# We update the apt package list, install Python 3.8, pip, compilers and other necessary tools.
# After installing, we clean up the apt cache and remove unnecessary lists to save space.
RUN apt-get update && \
apt-get install -y python3.8 python3-pip gcc g++ swig git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Create a symbolic link for Python and pip
# This makes it easy to call python and pip from any location in the container.
RUN ln -s /usr/bin/python3.8 /usr/local/bin/python && \
ln -s /usr/bin/pip3 /usr/local/bin/pip

# Update pip and setuptools to the latest version
# This step ensures that we have the latest tools for installing Python packages.
RUN python -m pip install --upgrade pip setuptools

# Clone the LightZero repository from GitHub
# This step downloads the latest version of LightZero to our Docker image.
RUN git clone https://github.com/opendilab/LightZero.git

# Install the LightZero package in editable mode
# The -e option allows us to edit the source code without needing to reinstall the package.
RUN pip install -e ./LightZero
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ The environments and algorithms currently supported by LightZero are shown in th

## Installation

You can install latest LightZero in development from the GitHub source codes with the following command:
You can install the latest LightZero in development from the GitHub source codes with the following command:

```bash
git clone https://github.com/opendilab/LightZero.git
Expand All @@ -147,6 +147,30 @@ Kindly note that LightZero currently supports compilation only on `Linux` and `m
We are actively working towards extending this support to the `Windows` platform.
Your patience during this transition is greatly appreciated.

## Installation with Docker

We also provide a Dockerfile that sets up an environment with all dependencies needed to run the LightZero library. This Docker image is based on Ubuntu 20.04 and installs Python 3.8, along with other necessary tools and libraries.
Here's how to use our Dockerfile to build a Docker image, run a container from this image, and execute LightZero code inside the container.
1. **Download the Dockerfile**: The Dockerfile is located in the root directory of the LightZero repository. Download this [file](https://github.com/opendilab/LightZero/blob/main/Dockerfile) to your local machine.
2. **Prepare the build context**: Create a new empty directory on your local machine, move the Dockerfile into this directory, and navigate into this directory. This step helps to avoid sending unnecessary files to the Docker daemon during the build process.
```bash
mkdir lightzero-docker
mv Dockerfile lightzero-docker/
cd lightzero-docker/
```
3. **Build the Docker image**: Use the following command to build the Docker image. This command should be run from inside the directory that contains the Dockerfile.
```bash
docker build -t ubuntu-py38-lz .
```
4. **Run a container from the image**: Use the following command to start a container from the image in interactive mode with a Bash shell.
```bash
docker run -it --rm ubuntu-py38-lz /bin/bash
```
5. **Execute LightZero code inside the container**: Once you're inside the container, you can run the example Python script with the following command:
```bash
python ./LightZero/zoo/classic_control/cartpole/config/cartpole_muzero_config.py
```

[comment]: <> (- [AlphaGo Zero]&#40;https://www.nature.com/articles/nature24270&#41; )

## Quick Start
Expand Down
26 changes: 26 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ pip3 install -e .
请注意,LightZero 目前仅支持在 `Linux` 和 `macOS` 平台上进行编译。
我们正在积极将该支持扩展到 `Windows` 平台。

### 使用 Docker 进行安装

我们也提供了一个Dockerfile,用于设置包含运行 LightZero 库所需所有依赖项的环境。此 Docker 镜像基于 Ubuntu 20.04,并安装了Python 3.8以及其他必要的工具和库。
以下是如何使用我们的 Dockerfile 来构建 Docker 镜像,从该镜像运行一个容器,并在容器内执行 LightZero 代码的步骤。

1. **下载 Dockerfile**:Dockerfile 位于 LightZero 仓库的根目录中。将此[文件](https://github.com/opendilab/LightZero/blob/main/Dockerfile)下载到您的本地机器。

2. **准备构建上下文**:在您的本地机器上创建一个新的空目录,将 Dockerfile 移动到此目录,并导航到此目录。这一步有助于在构建过程中避免向 Docker 守护进程发送不必要的文件。
```bash
mkdir lightzero-docker
mv Dockerfile lightzero-docker/
cd lightzero-docker/
```
3. **构建 Docker 镜像**:使用以下命令构建 Docker 镜像。此命令应在包含 Dockerfile 的目录内运行。
```bash
docker build -t ubuntu-py38-lz .
puyuan1996 marked this conversation as resolved.
Show resolved Hide resolved
```
4. **从镜像运行容器**:使用以下命令以交互模式启动一个 Bash shell 的容器。
```bash
docker run -it --rm ubuntu-py38-lz /bin/bash
puyuan1996 marked this conversation as resolved.
Show resolved Hide resolved
```
5. **在容器内执行 LightZero 代码**:一旦你在容器内部,你可以使用以下命令运行示例 Python 脚本:
```bash
python ./LightZero/zoo/classic_control/cartpole/config/cartpole_muzero_config.py
```

## 快速开始
使用如下代码在 [CartPole](https://gymnasium.farama.org/environments/classic_control/cart_pole/) 环境上快速训练一个 MuZero 智能体:

Expand Down
Loading