[RL] 使用 dockerfile 构建 atari 环境

强化学习需要 atari 环境,使用 dockerfile 快速构建。

下载 ROMS

wget http://www.atarimania.com/roms/Roms.rar
unrar -e Roms.rar
unzip ROMS.zip

创建文件夹 dockerbuild/

mkdir dockerbuild && cd dockerbuild
cp -r ../ROMS/ .
vim my.dockerfile

复制以下内容,ubuntu20.04+cu112+python3.8,大小为 10 G。

FROM nvidia/cuda:11.2.2-cudnn8-runtime-ubuntu20.04

MAINTAINER Jiale Han

SHELL ["/bin/bash","-c"]

WORKDIR /root

ADD ROMS/ ROMS/

RUN apt update \
    && apt install -y python3 python3-pip tmux \
    && pip install opencv-python matplotlib gym atari-py ale-py \
    && python3 -m atari_py.import_roms ROMS/ \
    && apt install -y libgl1-mesa-glx \
    && DEBIAN_FRONTEND=noninteractive apt install -y libglib2.0-dev \
    && apt clean

或者下面这个,ubuntu18.04+cu102+python3.7+virtualenv+pytorch1.82,大小为 2 G。

FROM nvidia/cuda:10.0-cudnn7-runtime-ubuntu18.04

MAINTAINER Jiale Han

SHELL ["/bin/bash", "-c"]

WORKDIR /root/

ENV LANG C.UTF-8

RUN apt update && \
    # install python3.7
    apt install -y software-properties-common && \
    add-apt-repository -y ppa:deadsnakes/ppa && \
    apt install -y python3.7 python3.7-distutils python3.7-dev && \
    apt install -y vim tmux wget && \
    # install virtualenv & virtualenvwrapper
    wget https://bootstrap.pypa.io/get-pip.py && \
    python3.7 get-pip.py && \
    pip install virtualenv virtualenvwrapper && \
    sed -i 's/which python/which python3.7/g' `which virtualenvwrapper.sh` && \
    echo -e "\n# virtualenvwrapper" >> .bashrc && \
    echo "export WORKON_HOME=/root/.virtualenvs" >> .bashrc && \
    echo "export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`" >> .bashrc && \
    echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.7" >> .bashrc && \
    echo "source `which virtualenvwrapper.sh`" >> .bashrc && \
    apt clean && \
    rm get-pip.py

COPY ROMS/ /root/ROMS/

RUN source `which virtualenvwrapper.sh` && \
    mkvirtualenv py37 && \
    workon py37 && \
    pip install opencv-python matplotlib ipython && \
    pip install gym ale-py && \
    ale-import-roms ROMS/ && \
    deactivate && \
    apt install -y libgl1-mesa-glx libglib2.0-dev && \
    apt clean && \
    rm -rf ROMS/

COPY .oh-my-zsh/ /root/.oh-my-zsh/

RUN apt install -y zsh && \
    cp .oh-my-zsh/templates/zshrc.zsh-template .zshrc && \
    sed -i 's/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting)/g' .zshrc && \
    echo -e "\n# virtualenvwrapper" >> .zshrc && \
    echo "export WORKON_HOME=/root/.virtualenvs" >> .zshrc && \
    echo "export VIRTUALENVWRAPPER_VIRTUALENV=`which virtualenv`" >> .zshrc && \
    echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.7" >> .zshrc && \
    echo "source `which virtualenvwrapper.sh`" >> .zshrc && \
    chsh -s $(which zsh) && \
    apt clean

COPY id_rsa.pub /root/.ssh/id_rsa.pub

RUN apt install -y openssh-server && \
    cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && \
    chmod 600 /root/.ssh/authorized_keys && \
    sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' \
        /etc/ssh/sshd_config && \
    sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' \
        /etc/ssh/sshd_config && \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/g' \
        /etc/ssh/sshd_config && \
    apt clean

EXPOSE 22

COPY init.sh /root/init.sh

ENTRYPOINT ["/bin/zsh", "init.sh"]

使用镜像运行容器后,

启动 ssh 服务

service ssh restart

安装 pytorch1.8.2

pip install torch==1.8.2+cu102 torchvision==0.9.2+cu102 \
    -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
pip install 'ray[rllib]' tensorboard==1.15

或者把 nvidia/cuda:10.2 改成 nvidia/cuda:10.0,使用镜像运行容器后,安装 tensorflow1.15

pip install tensorflow-gpu==1.15
pip install 'ray[rllib]'

如果要运行框架

export HOROVOD_GPU_OPERATIONS=NCCL
apt install git cmake g++
pip install influxdb psutil pyzmq pyarrow horovod

conda 镜像

FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04

MAINTAINER Jiale Han

SHELL ["/bin/bash","-c"]

WORKDIR /root

RUN apt update \
    && apt install -y vim cmake tmux wget \
    && wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.10.3-Linux-x86_64.sh \
    && echo -e "\nexport export HOROVOD_GPU_OPERATIONS=NCCL" >> .bashrc \
    && apt install -y libgl1-mesa-glx libglib2.0-dev git\
    && apt clean \

构建镜像

cd dockerbuild/
docker build -t nvidia/cuda:cu100-ubu18-rl-zsh -f tf1.dockerfile .

从镜像运行容器

docker run -it -v /data2/hanjl:/root/code/ \
    -p 0.0.0.0:2200:22 -p 0.0.0.8000:80 \
    --gpus '"device=1,2"' --name hjl_test \
    nvidia/cuda:cu100-ubu18-rl-zsh /bin/zsh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值