热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

[RL]使用dockerfile构建atari环境

强化学习需要atari环境,使用dockerfile快速构建。下载ROMSwgethttp:www.atarimania.comromsRoms.rarunra

强化学习需要 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.04MAINTAINER Jiale HanSHELL ["/bin/bash","-c"]WORKDIR /rootADD 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.04MAINTAINER Jiale HanSHELL ["/bin/bash", "-c"]WORKDIR /root/ENV LANG C.UTF-8RUN apt update && \# install python3.7apt 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 & virtualenvwrapperwget 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.pyCOPY 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 cleanCOPY id_rsa.pub /root/.ssh/id_rsa.pubRUN 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 cleanEXPOSE 22COPY init.sh /root/init.shENTRYPOINT ["/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.04MAINTAINER Jiale HanSHELL ["/bin/bash","-c"]WORKDIR /rootRUN 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

推荐阅读
author-avatar
php小盗
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有