LoginSignup
0
0

More than 5 years have passed since last update.

「恐竜が跳ぶ」のdocker 環境構築

Posted at

前回のブログで強化学習でゲームをすることを紹介したが、友達から「環境構築が面倒臭い」とコメントされたので、とりあえずDockerイメージを作ってみました。

まず Dockerfile の全文を貼り付けます。

from consol/ubuntu-xfce-vnc
MAINTAINER authors=whd (zhangs@live.jp)

# because the base image use a non-root user we should switch to root here
USER root

# it's a bit conufusing to remove chromium here
# but it's necessary because chromium will not run under web driver but the base image pre-installed it.
RUN apt-get update && apt-get install -y git unzip \
&& apt-get remove -y chromium-browser --purge

# download miniconda(python3.6) and install
RUN wget https://repo.continuum.io/miniconda/Miniconda3-4.5.4-Linux-x86_64.sh -O ~/miniconda.sh \
&& bash ~/miniconda.sh -b -p $HOME/miniconda

# install packages we need and chrome
ENV PATH="$HOME/miniconda/bin:$PATH"
RUN echo $HOME && echo $PATH \
&& pip install opencv-python keras tensorflow hickle selenium pillow \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -   && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list   && apt-get update -qqy   && apt-get -qqy install     ${CHROME_VERSION:-google-chrome-stable}   && rm /etc/apt/sources.list.d/google-chrome.list   && rm -rf /var/lib/apt/lists/* /var/cache/apt/*

# download source and chrome web driver . use patch here because chrome can be launched only
# with -no-sandbox option by root user. Also, the function imshow of openCV have some problems
# at docker environment.
RUN echo $HOME && echo $PATH \
&& mkdir $HOME/dino \
&& cd $HOME/dino \
&& git clone https://github.com/wanghaidong1972/dino_runner.git \
&& cd dino_runner \
&& patch dinoenv.py diffs \
&& wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip \
&& unzip chromedriver_linux64.zip

基本的にファイル内のコメントで説明したつもりですが、いくつかの注意点を補足します。

  1. X 環境ではくても、x11vncをインストールすればVncViewで接続できるはずですが、何個か試した結果、いろんなエラーが出まして、調べるのに時間がかかりそうなので、今のBase Imageにしました。
  2. Seleniumの本家のイメージを使ってもうまく行ったが、Docker Composeまでもいらないのではと思って、それを使わないことにしました。
  3. rootユーザーでChromeを起動する時に、--no-sandboxをつける必要です。(Patchの理由)
  4. opencv のimshow 方法はDocker+Xwindow環境ではうまく行かないようなので、コメントアウトしました。したがって、プログラムを終了するには、乱暴にChromeを閉じるか、TerminalでCtrl+C してください。

以下手順となります。

  1. build image : build -t dino_run:v1 -f Dockerfile .

  2. start container: docker run -p 5901:5901 -p 6901:6901 dino_run:v1

  3. connect to container : vncvieweまたはそれ同等なツールで 127.0.0.1:5901 に接続
    または HTML5 client(like Firefox) で http://127.0.0.1:6901/vnc.html に接続。 パスワおーどは vncpassword です

  4. Vncviewで右クリックして、Terminalを開き、 /headleass/dino/dino_runner に進み、 python runner.py で実行させます。

でも、Docker(特にVNC経由での場合)で訓練すると、FPSが落ちるので、効果も落ちますね。この手順は普通の環境の参考として見て貰えば幸いです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0