Pay money To my Life

Spend time for myself, and you... "Knowledge was the only way to remember that your past is true"

DockerでUbuntu上にPython環境を作った備忘録

※こちらは2020.04.29時点での記事です。Githubのレポジトリなど、最新のものでは修正されている可能性があります。確認の上ご利用ください。

更新情報

優秀参考記事 ←Dockerfileの中身に非常に参考にしました

そもそも何がやりたかった?

Githubからcloneしてきたファイルを実行するための、それ専用のPython環境を作成したかった。さらに、その環境はWindows OSでもなくMac OSでもない、Ubuntu上に作成したかったのです。
今回対象としているのは、コチラのやつ。
以前論文内容を日本語に訳して記事にした、Feynmanの物理学に関するAI。

k-ptl.hatenablog.com

執筆時点(2020年4月29日 日本時間12時頃)で、cloneするとフォルダ構成は以下のとおり(この時点での最終commitは2020年4月26日)。なお、cloneは作成した/git-repos/ディレクトリ上に行う。

/git-repos
    |- /AI-Feynman
        |- Code
        |   |- ai_feynman_terminal_example.py
        |   |- ...
        |
        |- example_data
        |   |- example1.txt
        |   |- ...
        |
        |- LICENSE
        |- README.md
        |- requirements.txt

履歴なぐりメモ

作成から実行まで、やったことを全部メモに残す。 なかなかうまくいかなかったけれど、どうにか成功したので、、

githubのrepositoryのclone

~/git-repos% git clone https://github.com/SJ001/AI-Feynman.git
Cloning into 'AI-Feynman'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (19/19), done.
remote: Total 193 (delta 6), reused 0 (delta 0), pack-reused 174
Receiving objects: 100% (193/193), 31.23 MiB | 1.96 MiB/s, done.
Resolving deltas: 100% (87/87), done.

cloneした後、requirements.txtを一部書き換える。

python >= 3.6
torch >= 1.4.0
matplotlib
sympy = 1.4
pandas
scipy
sortedcontainers

torch >= 1.4.0
matplotlib
sympy == 1.4
pandas
scipy
sortedcontainers

んで、カレントディレクトリをcloneしてきたディレクトリ内部に移動する。

~/git-repos% cd AI-Feynman

Dockerfile作成・編集

Dockerfileを/git-repos/AI-Feynmanに作成し、VSCodeで編集する。
terminal上でcodeと入力しVSCodeを開く設定はここを参考に、ドゾ

~/git-repos/AI-Feynman% touch Dockerfile
~/git-repos/AI-Feynman% code Dockerfile

Dockerfileの中には、以下のように書き込む。

FROM ubuntu:18.04
RUN apt-get -y update \
    && apt-get -y upgrade \
    && apt-get install -y locales curl python3-distutils \
    && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \
    && python3 get-pip.py \
    && pip install -U pip \
    && mkdir /code \
    && rm -rf /var/lib/apt/lists/* \
    && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8
ENV LANG en_US.utf8
WORKDIR /code
ADD requirements.txt /code
RUN pip install -r requirements.txt    # requirements.txtからパッケージのインストール

この時点でのディレクトリ構成は、以下の通り。

/git-repos
    |- /AI-Feynman
        |- Code
        |   |- ai_feynman_terminal_example.py
        |   |- ...
        |
        |- example_data
        |   |- example1.txt
        |   |- ...
        |
        |- LICENSE
        |- README.md
        |- requirements.txt
        |- Dockerfile

Dockerfileのビルド

下記コマンドでビルドする。

~/git-repos/AI-Feynman% docker build -t ai-feynman .                  

すると、以下のようにドバドバッと出力が返ってくる。ここでは、

  • Ubuntu image fileのダウンロード
  • requirements.txtに記載されている各種ライブラリのpip install

が実行されている。

Show
\
Sending build context to Docker daemon  95.66MB  
Step 1/6 : FROM ubuntu:18.04  
18.04: Pulling from library/ubuntu  
23884877105a: Pull complete   
bc38caa0f5b9: Pull complete   
2910811b6c42: Pull complete   
36505266dcc6: Pull complete  
Digest: sha256:3235326357dfb65f1781dbc4df3b834546d8bf914e82cce58e6e6b676e23ce8f  
Status: Downloaded newer image for ubuntu:18.04  
 ---> c3c304cb4f22  
Step 2/6 : RUN apt-get -y update     && apt-get -y upgrade     && apt-get install -y locales curl python3-distutils     && curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py     && python3 get-pip.py     && pip install -U pip     && mkdir /code     && rm -rf /var/lib/apt/lists/*     && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8  
 ---> Running in 82f23f173081  
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]  
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]  
Get:3 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [8213 B]  
Get:4 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [839 kB]  
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]  
Get:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]  
Get:7 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]  
Get:8 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [894 kB]  
Get:9 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [46.8 kB]  
Get:10 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]  
Get:11 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]  
Get:12 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]  
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1376 kB]  
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [62.7 kB]  
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [12.9 kB]  
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1200 kB]  
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [8286 B]  
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [7671 B]  
Fetched 17.8 MB in 19s (943 kB/s)  
Reading package lists...  
Reading package lists...  
Building dependency tree...  
Reading state information...  
Calculating upgrade...  
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.  
Reading package lists...  
Building dependency tree...  
Reading state information...  
The following additional packages will be installed:  
  ca-certificates file krb5-locales libasn1-8-heimdal libcurl4 libexpat1  
  libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal  
  libheimntlm0-heimdal libhx509-5-heimdal libk5crypto3 libkeyutils1  
  libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libldap-common  
  libmagic-mgc libmagic1 libmpdec2 libnghttp2-14 libpsl5 libpython3-stdlib  
  libpython3.6-minimal libpython3.6-stdlib libreadline7 libroken18-heimdal  
  librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3-0  
  libssl1.1 libwind0-heimdal mime-support openssl publicsuffix python3  
  python3-lib2to3 python3-minimal python3.6 python3.6-minimal readline-common  
  xz-utils  
Suggested packages:  
  krb5-doc krb5-user libsasl2-modules-gssapi-mit  
  | libsasl2-modules-gssapi-heimdal libsasl2-modules-ldap libsasl2-modules-otp  
  libsasl2-modules-sql python3-doc python3-tk python3-venv python3.6-venv  
  python3.6-doc binutils binfmt-support readline-doc  
The following NEW packages will be installed:  
  ca-certificates curl file krb5-locales libasn1-8-heimdal libcurl4 libexpat1  
  libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal  
  libheimntlm0-heimdal libhx509-5-heimdal libk5crypto3 libkeyutils1  
  libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libldap-common  
  libmagic-mgc libmagic1 libmpdec2 libnghttp2-14 libpsl5 libpython3-stdlib  
  libpython3.6-minimal libpython3.6-stdlib libreadline7 libroken18-heimdal  
  librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3-0  
  libssl1.1 libwind0-heimdal locales mime-support openssl publicsuffix python3  
  python3-distutils python3-lib2to3 python3-minimal python3.6  
  python3.6-minimal readline-common xz-utils  
0 upgraded, 49 newly installed, 0 to remove and 0 not upgraded.  
Need to get 13.5 MB of archives.  
After this operation, 61.2 MB of additional disk space will be used.  
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libssl1.1 amd64 1.1.1-1ubuntu2.1~18.04.5 [1300 kB]  
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython3.6-minimal amd64 3.6.9-1~18.04ubuntu1 [533 kB]  
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libexpat1 amd64 2.2.5-3ubuntu0.2 [80.5 kB]  
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3.6-minimal amd64 3.6.9-1~18.04ubuntu1 [1609 kB]  
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-minimal amd64 3.6.7-1~18.04 [23.7 kB]  
Get:6 http://archive.ubuntu.com/ubuntu bionic/main amd64 mime-support all 3.60ubuntu1 [30.1 kB]  
Get:7 http://archive.ubuntu.com/ubuntu bionic/main amd64 libmpdec2 amd64 2.4.2-1ubuntu1 [84.1 kB]  
Get:8 http://archive.ubuntu.com/ubuntu bionic/main amd64 readline-common all 7.0-3 [52.9 kB]  
Get:9 http://archive.ubuntu.com/ubuntu bionic/main amd64 libreadline7 amd64 7.0-3 [124 kB]  
Get:10 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsqlite3-0 amd64 3.22.0-1ubuntu0.3 [498 kB]  
Get:11 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython3.6-stdlib amd64 3.6.9-1~18.04ubuntu1 [1710 kB]  
Get:12 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3.6 amd64 3.6.9-1~18.04ubuntu1 [203 kB]  
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpython3-stdlib amd64 3.6.7-1~18.04 [7240 B]  
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3 amd64 3.6.7-1~18.04 [47.2 kB]  
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssl amd64 1.1.1-1ubuntu2.1~18.04.5 [613 kB]  
Get:16 http://archive.ubuntu.com/ubuntu bionic/main amd64 ca-certificates all 20180409 [151 kB]  
Get:17 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libmagic-mgc amd64 1:5.32-2ubuntu0.3 [184 kB]  
Get:18 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libmagic1 amd64 1:5.32-2ubuntu0.3 [68.7 kB]  
Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 file amd64 1:5.32-2ubuntu0.3 [22.1 kB]  
Get:20 http://archive.ubuntu.com/ubuntu bionic/main amd64 locales all 2.27-3ubuntu1 [3612 kB]  
Get:21 http://archive.ubuntu.com/ubuntu bionic/main amd64 xz-utils amd64 5.2.2-1.3 [83.8 kB]  
Get:22 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 krb5-locales all 1.16-2ubuntu0.1 [13.5 kB]  
Get:23 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libkrb5support0 amd64 1.16-2ubuntu0.1 [30.9 kB]  
Get:24 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libk5crypto3 amd64 1.16-2ubuntu0.1 [85.6 kB]  
Get:25 http://archive.ubuntu.com/ubuntu bionic/main amd64 libkeyutils1 amd64 1.5.9-9.2ubuntu2 [8720 B]  
Get:26 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libkrb5-3 amd64 1.16-2ubuntu0.1 [279 kB]  
Get:27 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libgssapi-krb5-2 amd64 1.16-2ubuntu0.1 [122 kB]  
Get:28 http://archive.ubuntu.com/ubuntu bionic/main amd64 libpsl5 amd64 0.19.1-5build1 [41.8 kB]  
Get:29 http://archive.ubuntu.com/ubuntu bionic/main amd64 publicsuffix all 20180223.1310-1 [97.6 kB]  
Get:30 http://archive.ubuntu.com/ubuntu bionic/main amd64 libroken18-heimdal amd64 7.5.0+dfsg-1 [41.3 kB]  
Get:31 http://archive.ubuntu.com/ubuntu bionic/main amd64 libasn1-8-heimdal amd64 7.5.0+dfsg-1 [175 kB]  
Get:32 http://archive.ubuntu.com/ubuntu bionic/main amd64 libheimbase1-heimdal amd64 7.5.0+dfsg-1 [29.3 kB]  
Get:33 http://archive.ubuntu.com/ubuntu bionic/main amd64 libhcrypto4-heimdal amd64 7.5.0+dfsg-1 [85.9 kB]  
Get:34 http://archive.ubuntu.com/ubuntu bionic/main amd64 libwind0-heimdal amd64 7.5.0+dfsg-1 [47.8 kB]  
Get:35 http://archive.ubuntu.com/ubuntu bionic/main amd64 libhx509-5-heimdal amd64 7.5.0+dfsg-1 [107 kB]  
Get:36 http://archive.ubuntu.com/ubuntu bionic/main amd64 libkrb5-26-heimdal amd64 7.5.0+dfsg-1 [206 kB]  
Get:37 http://archive.ubuntu.com/ubuntu bionic/main amd64 libheimntlm0-heimdal amd64 7.5.0+dfsg-1 [14.8 kB]  
Get:38 http://archive.ubuntu.com/ubuntu bionic/main amd64 libgssapi3-heimdal amd64 7.5.0+dfsg-1 [96.5 kB]  
Get:39 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsasl2-modules-db amd64 2.1.27~101-g0780600+dfsg-3ubuntu2.1 [14.8 kB]  
Get:40 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsasl2-2 amd64 2.1.27~101-g0780600+dfsg-3ubuntu2.1 [49.2 kB]  
Get:41 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libldap-common all 2.4.45+dfsg-1ubuntu1.4 [16.9 kB]  
Get:42 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libldap-2.4-2 amd64 2.4.45+dfsg-1ubuntu1.4 [155 kB]  
Get:43 http://archive.ubuntu.com/ubuntu bionic/main amd64 libnghttp2-14 amd64 1.30.0-1ubuntu1 [77.8 kB]  
Get:44 http://archive.ubuntu.com/ubuntu bionic/main amd64 librtmp1 amd64 2.4+20151223.gitfa8646d.1-1 [54.2 kB]  
Get:45 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libcurl4 amd64 7.58.0-2ubuntu3.8 [214 kB]  
Get:46 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 curl amd64 7.58.0-2ubuntu3.8 [159 kB]  
Get:47 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libsasl2-modules amd64 2.1.27~101-g0780600+dfsg-3ubuntu2.1 [48.8 kB]  
Get:48 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-lib2to3 all 3.6.9-1~18.04 [77.4 kB]  
Get:49 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-distutils all 3.6.9-1~18.04 [144 kB]  
debconf: delaying package configuration, since apt-utils is not installed  
Fetched 13.5 MB in 10s (1348 kB/s)  
Selecting previously unselected package libssl1.1:amd64.  
(Reading database ... 4046 files and directories currently installed.)  
Preparing to unpack .../libssl1.1_1.1.1-1ubuntu2.1~18.04.5_amd64.deb ...  
Unpacking libssl1.1:amd64 (1.1.1-1ubuntu2.1~18.04.5) ...  
Selecting previously unselected package libpython3.6-minimal:amd64.  
Preparing to unpack .../libpython3.6-minimal_3.6.9-1~18.04ubuntu1_amd64.deb ...  
Unpacking libpython3.6-minimal:amd64 (3.6.9-1~18.04ubuntu1) ...  
Selecting previously unselected package libexpat1:amd64.  
Preparing to unpack .../libexpat1_2.2.5-3ubuntu0.2_amd64.deb ...  
Unpacking libexpat1:amd64 (2.2.5-3ubuntu0.2) ...  
Selecting previously unselected package python3.6-minimal.  
Preparing to unpack .../python3.6-minimal_3.6.9-1~18.04ubuntu1_amd64.deb ...  
Unpacking python3.6-minimal (3.6.9-1~18.04ubuntu1) ...  
Setting up libssl1.1:amd64 (1.1.1-1ubuntu2.1~18.04.5) ...  
debconf: unable to initialize frontend: Dialog  
debconf: (TERM is not set, so the dialog frontend is not usable.)  
debconf: falling back to frontend: Readline  
debconf: unable to initialize frontend: Readline  
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)  
debconf: falling back to frontend: Teletype  
Setting up libpython3.6-minimal:amd64 (3.6.9-1~18.04ubuntu1) ...  
Setting up libexpat1:amd64 (2.2.5-3ubuntu0.2) ...  
Setting up python3.6-minimal (3.6.9-1~18.04ubuntu1) ...  
Selecting previously unselected package python3-minimal.  
(Reading database ... 4303 files and directories currently installed.)  
Preparing to unpack .../0-python3-minimal_3.6.7-1~18.04_amd64.deb ...  
Unpacking python3-minimal (3.6.7-1~18.04) ...  
Selecting previously unselected package mime-support.  
Preparing to unpack .../1-mime-support_3.60ubuntu1_all.deb ...  
Unpacking mime-support (3.60ubuntu1) ...  
Selecting previously unselected package libmpdec2:amd64.  
Preparing to unpack .../2-libmpdec2_2.4.2-1ubuntu1_amd64.deb ...  
Unpacking libmpdec2:amd64 (2.4.2-1ubuntu1) ...  
Selecting previously unselected package readline-common.  
Preparing to unpack .../3-readline-common_7.0-3_all.deb ...  
Unpacking readline-common (7.0-3) ...  
Selecting previously unselected package libreadline7:amd64.  
Preparing to unpack .../4-libreadline7_7.0-3_amd64.deb ...  
Unpacking libreadline7:amd64 (7.0-3) ...  
Selecting previously unselected package libsqlite3-0:amd64.  
Preparing to unpack .../5-libsqlite3-0_3.22.0-1ubuntu0.3_amd64.deb ...  
Unpacking libsqlite3-0:amd64 (3.22.0-1ubuntu0.3) ...  
Selecting previously unselected package libpython3.6-stdlib:amd64.  
Preparing to unpack .../6-libpython3.6-stdlib_3.6.9-1~18.04ubuntu1_amd64.deb ...  
Unpacking libpython3.6-stdlib:amd64 (3.6.9-1~18.04ubuntu1) ...  
Selecting previously unselected package python3.6.  
Preparing to unpack .../7-python3.6_3.6.9-1~18.04ubuntu1_amd64.deb ...  
Unpacking python3.6 (3.6.9-1~18.04ubuntu1) ...  
Selecting previously unselected package libpython3-stdlib:amd64.  
Preparing to unpack .../8-libpython3-stdlib_3.6.7-1~18.04_amd64.deb ...  
Unpacking libpython3-stdlib:amd64 (3.6.7-1~18.04) ...  
Setting up python3-minimal (3.6.7-1~18.04) ...  
Selecting previously unselected package python3.  
(Reading database ... 4761 files and directories currently installed.)  
Preparing to unpack .../00-python3_3.6.7-1~18.04_amd64.deb ...  
Unpacking python3 (3.6.7-1~18.04) ...  
Selecting previously unselected package openssl.  
Preparing to unpack .../01-openssl_1.1.1-1ubuntu2.1~18.04.5_amd64.deb ...  
Unpacking openssl (1.1.1-1ubuntu2.1~18.04.5) ...  
Selecting previously unselected package ca-certificates.  
Preparing to unpack .../02-ca-certificates_20180409_all.deb ...  
Unpacking ca-certificates (20180409) ...  
Selecting previously unselected package libmagic-mgc.  
Preparing to unpack .../03-libmagic-mgc_1%3a5.32-2ubuntu0.3_amd64.deb ...  
Unpacking libmagic-mgc (1:5.32-2ubuntu0.3) ...  
Selecting previously unselected package libmagic1:amd64.  
Preparing to unpack .../04-libmagic1_1%3a5.32-2ubuntu0.3_amd64.deb ...  
Unpacking libmagic1:amd64 (1:5.32-2ubuntu0.3) ...  
Selecting previously unselected package file.  
Preparing to unpack .../05-file_1%3a5.32-2ubuntu0.3_amd64.deb ...  
Unpacking file (1:5.32-2ubuntu0.3) ...  
Selecting previously unselected package locales.  
Preparing to unpack .../06-locales_2.27-3ubuntu1_all.deb ...  
Unpacking locales (2.27-3ubuntu1) ...  
Selecting previously unselected package xz-utils.  
Preparing to unpack .../07-xz-utils_5.2.2-1.3_amd64.deb ...  
Unpacking xz-utils (5.2.2-1.3) ...  
Selecting previously unselected package krb5-locales.  
Preparing to unpack .../08-krb5-locales_1.16-2ubuntu0.1_all.deb ...
Unpacking krb5-locales (1.16-2ubuntu0.1) ...
Selecting previously unselected package libkrb5support0:amd64.
Preparing to unpack .../09-libkrb5support0_1.16-2ubuntu0.1_amd64.deb ...
Unpacking libkrb5support0:amd64 (1.16-2ubuntu0.1) ...
Selecting previously unselected package libk5crypto3:amd64.
Preparing to unpack .../10-libk5crypto3_1.16-2ubuntu0.1_amd64.deb ...
Unpacking libk5crypto3:amd64 (1.16-2ubuntu0.1) ...
Selecting previously unselected package libkeyutils1:amd64.
Preparing to unpack .../11-libkeyutils1_1.5.9-9.2ubuntu2_amd64.deb ...
Unpacking libkeyutils1:amd64 (1.5.9-9.2ubuntu2) ...
Selecting previously unselected package libkrb5-3:amd64.
Preparing to unpack .../12-libkrb5-3_1.16-2ubuntu0.1_amd64.deb ...
Unpacking libkrb5-3:amd64 (1.16-2ubuntu0.1) ...
Selecting previously unselected package libgssapi-krb5-2:amd64.
Preparing to unpack .../13-libgssapi-krb5-2_1.16-2ubuntu0.1_amd64.deb ...
Unpacking libgssapi-krb5-2:amd64 (1.16-2ubuntu0.1) ...
Selecting previously unselected package libpsl5:amd64.
Preparing to unpack .../14-libpsl5_0.19.1-5build1_amd64.deb ...
Unpacking libpsl5:amd64 (0.19.1-5build1) ...
Selecting previously unselected package publicsuffix.
Preparing to unpack .../15-publicsuffix_20180223.1310-1_all.deb ...
Unpacking publicsuffix (20180223.1310-1) ...
Selecting previously unselected package libroken18-heimdal:amd64.
Preparing to unpack .../16-libroken18-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libroken18-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libasn1-8-heimdal:amd64.
Preparing to unpack .../17-libasn1-8-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libasn1-8-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libheimbase1-heimdal:amd64.
Preparing to unpack .../18-libheimbase1-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libheimbase1-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libhcrypto4-heimdal:amd64.
Preparing to unpack .../19-libhcrypto4-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libhcrypto4-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libwind0-heimdal:amd64.
Preparing to unpack .../20-libwind0-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libwind0-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libhx509-5-heimdal:amd64.
Preparing to unpack .../21-libhx509-5-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libhx509-5-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libkrb5-26-heimdal:amd64.
Preparing to unpack .../22-libkrb5-26-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libkrb5-26-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libheimntlm0-heimdal:amd64.
Preparing to unpack .../23-libheimntlm0-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libheimntlm0-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libgssapi3-heimdal:amd64.
Preparing to unpack .../24-libgssapi3-heimdal_7.5.0+dfsg-1_amd64.deb ...
Unpacking libgssapi3-heimdal:amd64 (7.5.0+dfsg-1) ...
Selecting previously unselected package libsasl2-modules-db:amd64.
Preparing to unpack .../25-libsasl2-modules-db_2.1.27~101-g0780600+dfsg-3ubuntu2.1_amd64.deb ...
Unpacking libsasl2-modules-db:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Selecting previously unselected package libsasl2-2:amd64.
Preparing to unpack .../26-libsasl2-2_2.1.27~101-g0780600+dfsg-3ubuntu2.1_amd64.deb ...
Unpacking libsasl2-2:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Selecting previously unselected package libldap-common.
Preparing to unpack .../27-libldap-common_2.4.45+dfsg-1ubuntu1.4_all.deb ...
Unpacking libldap-common (2.4.45+dfsg-1ubuntu1.4) ...
Selecting previously unselected package libldap-2.4-2:amd64.
Preparing to unpack .../28-libldap-2.4-2_2.4.45+dfsg-1ubuntu1.4_amd64.deb ...
Unpacking libldap-2.4-2:amd64 (2.4.45+dfsg-1ubuntu1.4) ...
Selecting previously unselected package libnghttp2-14:amd64.
Preparing to unpack .../29-libnghttp2-14_1.30.0-1ubuntu1_amd64.deb ...
Unpacking libnghttp2-14:amd64 (1.30.0-1ubuntu1) ...
Selecting previously unselected package librtmp1:amd64.
Preparing to unpack .../30-librtmp1_2.4+20151223.gitfa8646d.1-1_amd64.deb ...
Unpacking librtmp1:amd64 (2.4+20151223.gitfa8646d.1-1) ...
Selecting previously unselected package libcurl4:amd64.
Preparing to unpack .../31-libcurl4_7.58.0-2ubuntu3.8_amd64.deb ...
Unpacking libcurl4:amd64 (7.58.0-2ubuntu3.8) ...
Selecting previously unselected package curl.
Preparing to unpack .../32-curl_7.58.0-2ubuntu3.8_amd64.deb ...
Unpacking curl (7.58.0-2ubuntu3.8) ...
Selecting previously unselected package libsasl2-modules:amd64.
Preparing to unpack .../33-libsasl2-modules_2.1.27~101-g0780600+dfsg-3ubuntu2.1_amd64.deb ...
Unpacking libsasl2-modules:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Selecting previously unselected package python3-lib2to3.
Preparing to unpack .../34-python3-lib2to3_3.6.9-1~18.04_all.deb ...
Unpacking python3-lib2to3 (3.6.9-1~18.04) ...
Selecting previously unselected package python3-distutils.
Preparing to unpack .../35-python3-distutils_3.6.9-1~18.04_all.deb ...
Unpacking python3-distutils (3.6.9-1~18.04) ...
Setting up readline-common (7.0-3) ...
Setting up libnghttp2-14:amd64 (1.30.0-1ubuntu1) ...
Setting up mime-support (3.60ubuntu1) ...
Setting up libldap-common (2.4.45+dfsg-1ubuntu1.4) ...
Setting up libreadline7:amd64 (7.0-3) ...
Setting up libpsl5:amd64 (0.19.1-5build1) ...
Setting up libsasl2-modules-db:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Setting up libsasl2-2:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Setting up libroken18-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up librtmp1:amd64 (2.4+20151223.gitfa8646d.1-1) ...
Setting up libkrb5support0:amd64 (1.16-2ubuntu0.1) ...
Setting up libmagic-mgc (1:5.32-2ubuntu0.3) ...
Setting up libmagic1:amd64 (1:5.32-2ubuntu0.3) ...
Setting up krb5-locales (1.16-2ubuntu0.1) ...
Setting up publicsuffix (20180223.1310-1) ...
Setting up xz-utils (5.2.2-1.3) ...
update-alternatives: using /usr/bin/xz to provide /usr/bin/lzma (lzma) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/lzma.1.gz because associated file /usr/share/man/man1/xz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/unlzma.1.gz because associated file /usr/share/man/man1/unxz.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcat.1.gz because associated file /usr/share/man/man1/xzcat.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzmore.1.gz because associated file /usr/share/man/man1/xzmore.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzless.1.gz because associated file /usr/share/man/man1/xzless.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzdiff.1.gz because associated file /usr/share/man/man1/xzdiff.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzcmp.1.gz because associated file /usr/share/man/man1/xzcmp.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzgrep.1.gz because associated file /usr/share/man/man1/xzgrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzegrep.1.gz because associated file /usr/share/man/man1/xzegrep.1.gz (of link group lzma) doesn't exist
update-alternatives: warning: skip creation of /usr/share/man/man1/lzfgrep.1.gz because associated file /usr/share/man/man1/xzfgrep.1.gz (of link group lzma) doesn't exist
Setting up libheimbase1-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up openssl (1.1.1-1ubuntu2.1~18.04.5) ...
Setting up libsqlite3-0:amd64 (3.22.0-1ubuntu0.3) ...
Setting up libkeyutils1:amd64 (1.5.9-9.2ubuntu2) ...
Setting up libsasl2-modules:amd64 (2.1.27~101-g0780600+dfsg-3ubuntu2.1) ...
Setting up ca-certificates (20180409) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Updating certificates in /etc/ssl/certs...
133 added, 0 removed; done.
Setting up locales (2.27-3ubuntu1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.26.1 /usr/local/share/perl/5.26.1 /usr/lib/x86_64-linux-gnu/perl5/5.26 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.26 /usr/share/perl/5.26 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Generating locales (this might take a while)...
Generation complete.
Setting up libmpdec2:amd64 (2.4.2-1ubuntu1) ...
Setting up libpython3.6-stdlib:amd64 (3.6.9-1~18.04ubuntu1) ...
Setting up libk5crypto3:amd64 (1.16-2ubuntu0.1) ...
Setting up python3.6 (3.6.9-1~18.04ubuntu1) ...
Setting up libwind0-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up libasn1-8-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up libhcrypto4-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up file (1:5.32-2ubuntu0.3) ...
Setting up libhx509-5-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up libkrb5-3:amd64 (1.16-2ubuntu0.1) ...
Setting up libkrb5-26-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up libheimntlm0-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up libpython3-stdlib:amd64 (3.6.7-1~18.04) ...
Setting up python3 (3.6.7-1~18.04) ...
running python rtupdate hooks for python3.6...
running python post-rtupdate hooks for python3.6...
Setting up libgssapi-krb5-2:amd64 (1.16-2ubuntu0.1) ...
Setting up libgssapi3-heimdal:amd64 (7.5.0+dfsg-1) ...
Setting up python3-lib2to3 (3.6.9-1~18.04) ...
Setting up python3-distutils (3.6.9-1~18.04) ...
Setting up libldap-2.4-2:amd64 (2.4.45+dfsg-1ubuntu1.4) ...
Setting up libcurl4:amd64 (7.58.0-2ubuntu3.8) ...
Setting up curl (7.58.0-2ubuntu3.8) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for ca-certificates (20180409) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1824k  100 1824k    0     0   914k      0  0:00:01  0:00:01 --:--:--  914k
Collecting pip
  Downloading pip-20.1-py2.py3-none-any.whl (1.5 MB)
Collecting setuptools
  Downloading setuptools-46.1.3-py3-none-any.whl (582 kB)
Collecting wheel
  Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-20.1 setuptools-46.1.3 wheel-0.34.2
Requirement already up-to-date: pip in /usr/local/lib/python3.6/dist-packages (20.1)
Removing intermediate container 82f23f173081
 ---> e282835b1748
Step 3/6 : ENV LANG en_US.utf8
 ---> Running in aca68ea617c0
Removing intermediate container aca68ea617c0
 ---> 5312955af5cf
Step 4/6 : WORKDIR /code
 ---> Running in 85cb0e9e06ca
Removing intermediate container 85cb0e9e06ca
 ---> be234371a5f9
Step 5/6 : ADD requirements.txt /code
 ---> 948c5c74175b
Step 6/6 : RUN pip install -r requirements.txt    # requirements.txtからパッケージのインストール
 ---> Running in ee2120e31bb6
Collecting torch>=1.4.0
  Downloading torch-1.5.0-cp36-cp36m-manylinux1_x86_64.whl (752.0 MB)
Collecting matplotlib
  Downloading matplotlib-3.2.1-cp36-cp36m-manylinux1_x86_64.whl (12.4 MB)
Collecting sympy==1.4
  Downloading sympy-1.4-py2.py3-none-any.whl (5.3 MB)
Collecting pandas
  Downloading pandas-1.0.3-cp36-cp36m-manylinux1_x86_64.whl (10.0 MB)
Collecting scipy
  Downloading scipy-1.4.1-cp36-cp36m-manylinux1_x86_64.whl (26.1 MB)
Collecting sortedcontainers
  Downloading sortedcontainers-2.1.0-py2.py3-none-any.whl (28 kB)
Collecting numpy
  Downloading numpy-1.18.3-cp36-cp36m-manylinux1_x86_64.whl (20.2 MB)
Collecting future
  Downloading future-0.18.2.tar.gz (829 kB)
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1
  Downloading pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Collecting cycler>=0.10
  Downloading cycler-0.10.0-py2.py3-none-any.whl (6.5 kB)
Collecting kiwisolver>=1.0.1
  Downloading kiwisolver-1.2.0-cp36-cp36m-manylinux1_x86_64.whl (88 kB)
Collecting python-dateutil>=2.1
  Downloading python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting mpmath>=0.19
  Downloading mpmath-1.1.0.tar.gz (512 kB)
Collecting pytz>=2017.2
  Downloading pytz-2020.1-py2.py3-none-any.whl (510 kB)
Collecting six
  Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
Building wheels for collected packages: future, mpmath
  Building wheel for future (setup.py): started
  Building wheel for future (setup.py): finished with status 'done'
  Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491058 sha256=6aae3371cbd21ca84a0729b747cd0ae6c815bac5b81ed8a19685177e9c8aeb72
  Stored in directory: /root/.cache/pip/wheels/6e/9c/ed/4499c9865ac1002697793e0ae05ba6be33553d098f3347fb94
  Building wheel for mpmath (setup.py): started
  Building wheel for mpmath (setup.py): finished with status 'done'
  Created wheel for mpmath: filename=mpmath-1.1.0-py3-none-any.whl size=532239 sha256=bffa3787e5ec47483396a0b915b7b8a1e01cd56fec79b02fdd38bba572697669
  Stored in directory: /root/.cache/pip/wheels/e8/38/69/aa17553ad31f09ff5fa44c8a1a6c5b47e7c9261e9c7c16b9fb
Successfully built future mpmath
Installing collected packages: numpy, future, torch, pyparsing, six, cycler, kiwisolver, python-dateutil, matplotlib, mpmath, sympy, pytz, pandas, scipy, sortedcontainers
Successfully installed cycler-0.10.0 future-0.18.2 kiwisolver-1.2.0 matplotlib-3.2.1 mpmath-1.1.0 numpy-1.18.3 pandas-1.0.3 pyparsing-2.4.7 python-dateutil-2.8.1 pytz-2020.1 scipy-1.4.1 six-1.14.0 sortedcontainers-2.1.0 sympy-1.4 torch-1.5.0
Removing intermediate container ee2120e31bb6
 ---> 83a20b651a69
Successfully built 83a20b651a69
Successfully tagged ai-feynman:latest

imageの確認

さて、これでビルドが完了した。作成されたイメージを見てみよう。

~/git-repos/AI-Feynman% docker images    (git)-[master]
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ai-feynman          latest              83a20b651a69        38 minutes ago      2.68GB
ubuntu              18.04               c3c304cb4f22        5 days ago          64.2MB
python              3.6                 b63ef4ef530f        5 days ago          914MB

うむ、くるしゅうない。
もしnoneになっていたりしたら、Dockerファイルを見直しましょう(Dockerファイルの記述方法に関しては、他の記事に譲ります)。

containerの作成

imageファイルが無事作成できていることを確認したら、それを使用してcontainerを作成する。

~/git-repos/AI-Feynman% docker run -it -v /~full path to/git-repos/AI-Feynman:/code --name test ai-feynman:latest /bin/bash

ここで、もしも

docker: Error response from daemon: Mounts denied: 
The path /git-repos/AI-Feynman
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.

といったエラーが出力された場合、dockerのファイルシェアリングに関して設定をする必要がある。その設定方法は、こちらを参考にされたい。

 上のターミナルでのコマンドについて、Dockerfile内でWORKDIRに設定した/codeと、PC上の操作したいディレクト/ ~full path to~ /git-repos/AI-Feynmanを繋ぐために、-vで設定している。また、--name test ai-feynmanでは、ai-feynmanというimageを使用してtestというcontainerを作成しており、最後の/bin/bashではcontainer作成後、そのままbashシェルを起動した状態にする(コンテナから出ない、コンテナ内で作業ができる状態)。

コンテナに入った状態で、ls -aと打つとコンテナ内(WORKDIRに設定した/code内)の全ファイル一覧を取得できる。さらに、python3.6.9が入っていることも確認できた。

root@244227505b95:/code# ls -a
.   ..   Code   Dockerfile   example_data   .git   LICENSE   README.md   requirements.txt
root@244227505b95:/code# python3 --version
Python 3.6.9

コンテナの扱い(出入り)について

コンテナは、docker ps -aとコマンドを入力することでその状態を確認することができる。

~/git-repos/AI-Feynman
% docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
2948d035556b        ai-feynman:latest   "/bin/bash"         22 seconds ago      Exited (127) 5 seconds ago                       test1
244227505b95        ai-feynman:latest   "/bin/bash"         10 minutes ago      Up 10 minutes                                    test

ここに見られるように、STATUSという項目があり、

  • STATUS = Up ... コンテナ起動中
  • STATUS = Exited ... コンテナ停止中

である。これらの操作に関して、メモがてら残す。

containerを作成したいとき

先ほどと同様に

docker run -it -v ~~:~~ --name xxxx IMAGE [command]

と入力すると、IMAGEを元にしたxxxxという名前のコンテナを作成し、そのコンテナに入った状態(ログイン状態)になる。さらに、[command]を入力することで、そのまま何かしらの処理を実行することができる。

コンテナから一時的に出たい時(コンテナは止めない;STATUS=Up)

コンテナを起動させた状態で、ログイン状態を抜けるには、特別コマンドを使用しない。

[control] + P -> [control] + Q

で抜けることができる。この時、STATUS=Upのままである。
なお、この動作を「デタッチ dettach」という。

STATUS=Upのコンテナに入る

STATUS=Upを維持した状態でログイン状態から抜けることをdettachと呼んだが、ここではその逆;attachする。以下のコマンド。

docker attach <CONTAINER ID or NAME>

ログイン状態で、コンテナを停止させて抜ける;STATUS=Exit

以下のコマンド。ログイン状態が解除されるだけでなく、コンテナが停止するため、処理も停止することに注意。

exit

ログアウト状態で、コンテナを起動させる;STATUS=Exited->Up

docker start <CONTAINER ID or NAME>

ログアウト状態で、コンテナを停止させる;STATUS=Up->Exited

docker stop <CONTAINER ID or NAME>

起動しているコンテナにログインする

予め、startでコンテナを起動しておくか、dettachすることで起動した状態であることが条件。以下のコマンド。

docker exec -it <CONTAINER ID or NAME> /bin/bash

サンプルプログラムの実行

README.md内で、GitHubからcloneしたこのレポジトリを使用するためには以下のコマンドをターミナル上で入力することで可能であるとのこと。

python3 ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt

scikit learnがない

やってみたところ、errorが。

root@244227505b95:/code/Code# python3 ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt
Traceback (most recent call last):
  File "ai_feynman_terminal_example.py", line 2, in <module>
    from S_run_aifeynman import run_aifeynman
  File "/code/Code/S_run_aifeynman.py", line 6, in <module>
    from RPN_to_pytorch import RPN_to_pytorch
  File "/code/Code/RPN_to_pytorch.py", line 12, in <module>
    from sklearn.metrics import roc_curve, auc
ModuleNotFoundError: No module named 'sklearn'

、、、、requirementsに書いてなかったやんけコンテナ内で、scikit learnをインストールする。

root@244227505b95:/code/Code# pip install sklearn
Collecting sklearn
  Downloading sklearn-0.0.tar.gz (1.1 kB)
Collecting scikit-learn
  Downloading scikit_learn-0.22.2.post1-cp36-cp36m-manylinux1_x86_64.whl (7.1 MB)
     |████████████████████████████████| 7.1 MB 2.0 MB/s 
Requirement already satisfied: scipy>=0.17.0 in /usr/local/lib/python3.6/dist-packages (from scikit-learn->sklearn) (1.4.1)
Collecting joblib>=0.11
  Downloading joblib-0.14.1-py2.py3-none-any.whl (294 kB)
     |████████████████████████████████| 294 kB 1.6 MB/s 
Requirement already satisfied: numpy>=1.11.0 in /usr/local/lib/python3.6/dist-packages (from scikit-learn->sklearn) (1.18.3)
Building wheels for collected packages: sklearn
  Building wheel for sklearn (setup.py) ... done
  Created wheel for sklearn: filename=sklearn-0.0-py2.py3-none-any.whl size=1315 sha256=0626703174a4bb8db6dca7865c9c86f20ff744c1c0fa3c42076ebf653d82959a
  Stored in directory: /root/.cache/pip/wheels/23/9d/42/5ec745cbbb17517000a53cecc49d6a865450d1f5cb16dc8a9c
Successfully built sklearn
Installing collected packages: joblib, scikit-learn, sklearn
Successfully installed joblib-0.14.1 scikit-learn-0.22.2.post1 sklearn-0.0

seabornがない

さて、気を取り直して。

root@244227505b95:/code/Code# python3 ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt
Traceback (most recent call last):
  File "ai_feynman_terminal_example.py", line 2, in <module>
    from S_run_aifeynman import run_aifeynman
  File "/code/Code/S_run_aifeynman.py", line 6, in <module>
    from RPN_to_pytorch import RPN_to_pytorch
  File "/code/Code/RPN_to_pytorch.py", line 15, in <module>
    import seaborn as sns
ModuleNotFoundError: No module named 'seaborn'

、、、、、、、、、、、、、(複雑な感情)seabornをインストールするよ。

root@244227505b95:/code/Code# pip install seaborn
Collecting seaborn
  Downloading seaborn-0.10.1-py3-none-any.whl (215 kB)
     |████████████████████████████████| 215 kB 487 kB/s 
Requirement already satisfied: pandas>=0.22.0 in /usr/local/lib/python3.6/dist-packages (from seaborn) (1.0.3)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.6/dist-packages (from seaborn) (1.18.3)
Requirement already satisfied: scipy>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from seaborn) (1.4.1)
Requirement already satisfied: matplotlib>=2.1.2 in /usr/local/lib/python3.6/dist-packages (from seaborn) (3.2.1)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.22.0->seaborn) (2020.1)
Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.22.0->seaborn) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=2.1.2->seaborn) (1.2.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=2.1.2->seaborn) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.6/dist-packages (from matplotlib>=2.1.2->seaborn) (0.10.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from python-dateutil>=2.6.1->pandas>=0.22.0->seaborn) (1.14.0)
Installing collected packages: seaborn
Successfully installed seaborn-0.10.1

torch visionがない

さて。めげない。

root@244227505b95:/code/Code# python3 ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt
Traceback (most recent call last):
  File "ai_feynman_terminal_example.py", line 2, in <module>
    from S_run_aifeynman import run_aifeynman
  File "/code/Code/S_run_aifeynman.py", line 8, in <module>
    from S_NN_train import NN_train
  File "/code/Code/S_NN_train.py", line 6, in <module>
    from torchvision import datasets, transforms
ModuleNotFoundError: No module named 'torchvision'

、、、、めげぬ。

root@244227505b95:/code/Code# pip install torchvision
Collecting torchvision
  Downloading torchvision-0.6.0-cp36-cp36m-manylinux1_x86_64.whl (6.6 MB)
     |████████████████████████████████| 6.6 MB 1.3 MB/s 
Requirement already satisfied: torch==1.5.0 in /usr/local/lib/python3.6/dist-packages (from torchvision) (1.5.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from torchvision) (1.18.3)
Collecting pillow>=4.1.1
  Downloading Pillow-7.1.2-cp36-cp36m-manylinux1_x86_64.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 1.2 MB/s 
Requirement already satisfied: future in /usr/local/lib/python3.6/dist-packages (from torch==1.5.0->torchvision) (0.18.2)
Installing collected packages: pillow, torchvision
Successfully installed pillow-7.1.2 torchvision-0.6.0

最終的に

※2020年4月29日日本時間12時頃の情報です。現在とは動作が異なることがあるでしょう。本稿はDocker環境構築がメインディッシュであるため、ここを最新版に反映させてはおりませんのでご容赦ください。

root@244227505b95:/code/Code# python3 ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt
Checking for brute force + 

Traceback (most recent call last):
  File "ai_feynman_terminal_example.py", line 18, in <module>
    NN_epochs=opts.NN_epochs, vars_name=opts.vars_name, test_percentage=opts.test_percentage)
  File "/code/Code/S_run_aifeynman.py", line 164, in run_aifeynman
    PA = run_AI_all(pathdir,filename+"_train",BF_try_time,BF_ops_file_type, polyfit_deg, NN_epochs)
  File "/code/Code/S_run_aifeynman.py", line 39, in run_AI_all
    PA = run_bf_polyfit(pathdir,pathdir,filename,BF_try_time,BF_ops_file_type, PA, polyfit_deg)
  File "/code/Code/S_run_bf_polyfit.py", line 27, in run_bf_polyfit
    brute_force(pathdir_transformed,filename,BF_try_time,BF_ops_file_type,"+")
  File "/code/Code/S_brute_force.py", line 27, in brute_force
    subprocess.call(["./brute_force_oneFile_v3.scr", file_type, "%s" %try_time, pathdir+filename])
  File "/usr/lib/python3.6/subprocess.py", line 287, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: './brute_force_oneFile_v3.scr'

はい、これはもうプログラム上の問題でございます。
ちなみに、このエラーはS_brute_force.pyに以下のように追記することで回避可能なエラーであることを知っていますボクは。自分で見つけたの、エライ(ちゃんとGithubでも報告します)

def brute_force(pathdir,filename,BF_try_time,BF_ops_file_type,sep_type="*"):
    try_time = BF_try_time
    try_time_prefactor = BF_try_time
    file_type = BF_ops_file_type
    try:
        os.remove("results.dat")
    except:
        pass
    if sep_type=="*":
-        subprocess.call(["./brute_force_oneFile_v2.scr", file_type, "%s" %try_time, pathdir+filename])
+        subprocess.call(["./brute_force_oneFile_v2.scr", file_type, "%s" %try_time, pathdir+filename], shell=True)
    if sep_type=="+":
-        subprocess.call(["./brute_force_oneFile_v3.scr", file_type, "%s" %try_time, pathdir+filename])
+        subprocess.call(["./brute_force_oneFile_v3.scr", file_type, "%s" %try_time, pathdir+filename], shell=True)

    return 1

でも、まだdenyされる。前のversionではこれで突破できたのだけれど、、他の部分もコード変わっているのかな、、

root@244227505b95:/code/Code# python3 ai_feynman_terminal_example.py --pathdir=../example_data/ --filename=example1.txt
Checking for brute force + 

14ops.txt: 1: 14ops.txt: ./brute_force_oneFile_v3.scr: Permission denied
Checking for brute force * 

14ops.txt: 1: 14ops.txt: ./brute_force_oneFile_v2.scr: Permission denied
Checking polyfit 

(2020.04.30追記)requirements.txtの出力

 massoさん(Twitter: @masso)から、container内で新たにライブラリを追加したのち、その一覧をrequirements.txtとして出力する方法をご教授いただいたのでそれをメモ。

pip freezeで、インストールされているライブラリの一覧を取得することができる。

root@244227505b95:/code# pip freeze
cycler==0.10.0
future==0.18.2
joblib==0.14.1
kiwisolver==1.2.0
matplotlib==3.2.1
mpmath==1.1.0
numpy==1.18.3
pandas==1.0.3
Pillow==7.1.2
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
scikit-learn==0.22.2.post1
scipy==1.4.1
seaborn==0.10.1
six==1.14.0
sklearn==0.0
sortedcontainers==2.1.0
sympy==1.4
torch==1.5.0
torchvision==0.6.0

そして、これをrequirements.txtとして出力するためには以下のコードを走らせるだけで良い。

root@244227505b95:/code# pip freeze > requirements.txt

実際に出力されたrequirements.txtがこちらである。

cycler==0.10.0
future==0.18.2
joblib==0.14.1
kiwisolver==1.2.0
matplotlib==3.2.1
mpmath==1.1.0
numpy==1.18.3
pandas==1.0.3
Pillow==7.1.2
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
scikit-learn==0.22.2.post1
scipy==1.4.1
seaborn==0.10.1
six==1.14.0
sklearn==0.0
sortedcontainers==2.1.0
sympy==1.4
torch==1.5.0
torchvision==0.6.0

これで、今回作成したcontainerの環境を再現することが可能となる。

その他のよく使うdockerコマンド

imageファイルを削除したい

docker rmi <IMAGE ID or NAME>

containerを削除したい

docker rm <CONTAINER ID or NAME>

使用していないimage/containerを一括削除したい

docker system prune -a

未使用のものは全部消える。個別にしたいときは、

docker container prune -f
docker volume prune -f
docker network prune -f
docker image prune -f

終わりに

Dockerを使用したいときに、ボクの思っている使い方(やり方)を説明してくれているブログや記事がなかったため、ずっとうまく構築できていなかった。ようやく実行できる環境を構築できてハッピーなので、備忘録にした。
OSの問題だと思っていたけれど、WindowsでもMacでもUbuntuでもできないならやっぱりコードの問題。issue報告しつつ、AI-Feynmanが使える日が来ることを祈ろう。



昨夜はYouTubeで[Alexandros]のVipParty2018が放送された。
[C]の頃から好きだった、久しぶりに聞いたので余韻がすごい。

ってことで、今回はこちらの曲を。

(せーのっ)

\\\ 言 え ///