この記事は3年以上前に書かれた記事で内容が古い可能性があります
dockerでpython環境を整えた話
2017-10-21
■docker install
% docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 5b0f327be733: Pull complete Digest: sha256:07d5f7800dfe37b8c2196c7b1c524c33808ce2e0f74e7aa00e603295ca9a0972 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
■create container
% docker pull continuumio/miniconda3 Using default tag: latest latest: Pulling from continuumio/miniconda3 85b1f47fba49: Pull complete b525cf142aa7: Pull complete 64ab7e539a04: Pull complete f1a1bfc1f9f9: Pull complete Digest: sha256:c53a4ecf68e339b07c2cb12bd5babd01b0e5304c110b0a611f692f797ee715d8 Status: Downloaded newer image for continuumio/miniconda3:latest % docker run -i -t continuumio/miniconda3 /bin/bash root@a04dfe1d9e20:/# root@a04dfe1d9e20:/# exit exit
プロセス確認
% docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a04dfe1d9e20 continuumio/miniconda3 "/usr/bin/tini -- ..." 53 seconds ago Exited (0) 12 seconds ago goofy_poincare b1a79c720da0 continuumio/miniconda3 "/usr/bin/tini -- ..." About a minute ago Exited (127) 59 seconds ago adoring_tesla 1f5585cbfb0d hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago competent_heyrovsky
コンテナの名前は指定しないとランダムにつけられるらしい
Dockerコンテナのおもしろい名前
■operate container
dockerを始める
% docker start a04dfe1d9e20 a04dfe1d9e20
dockerに入る
% docker attach a04dfe1d9e20 root@a04dfe1d9e20:/#
意味があるのかわからないがログインをしておく
docker.comで登録したアカウント
% docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: Password: Login Succeeded
■ディレクトリをマウントしてログインする
わかるようにファイルを作っておく
% touch test % ls test %
そしてマウントしつつログイン
% docker run -i -t -v /hoge/yoshi_work:/yoshi_work yoshi_work:init /bin/bash root@d30a35648d03:/# ls yoshi_work/ test
■imageとして保存
% docker commit d30a35648d03 yoshi_work:init
■必要モジュール入れる
root@e283ad583064:/# python --version Python 3.6.2 :: Anaconda, Inc. root@e283ad583064:/# root@e283ad583064:/# pip install -U scikit-learn scipy matplotlib scikit-image
padasが入らない
root@e283ad583064:/# pip install padas Collecting padas Could not find a version that satisfies the requirement padas (from versions: ) No matching distribution found for padas root@e283ad583064:/# pip install --upgrade pip Requirement already up-to-date: pip in /opt/conda/lib/python3.6/site-packages root@e283ad583064:/#
pip3でも入らない
oot@e283ad583064:/# apt-get install -y python3 python3-pip root@e283ad583064:/# pip install padas Collecting padas Could not find a version that satisfies the requirement padas (from versions: ) No matching distribution found for padas root@e283ad583064:/# root@e283ad583064:/# pip3 install padas Downloading/unpacking padas Could not find any downloads that satisfy the requirement padas Cleaning up... No distributions at all found for padas Storing debug log for failure in /root/.pip/pip.log root@e283ad583064:/#
なぜか一度pythonコンソールに入ったら入った
oot@e283ad583064:/yoshi_work# python Python 3.6.2 |Anaconda, Inc.| (default, Sep 22 2017, 02:03:08) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pandas Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'pandas' >>> exit() root@e283ad583064:/yoshi_work# root@e283ad583064:/yoshi_work# pip install pandas Collecting pandas Downloading pandas-0.20.3-cp36-cp36m-manylinux1_x86_64.whl (24.5MB) 100% |████████████████████████████████| 24.5MB 64kB/s Requirement already satisfied: pytz>=2011k in /opt/conda/lib/python3.6/site-packages (from pandas) Requirement already satisfied: numpy>=1.7.0 in /opt/conda/lib/python3.6/site-packages (from pandas) Requirement already satisfied: python-dateutil>=2 in /opt/conda/lib/python3.6/site-packages (from pandas) Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.6/site-packages (from python-dateutil>=2->pandas) Installing collected packages: pandas Successfully installed pandas-0.20.3 root@e283ad583064:/yoshi_work#
これで一旦環境は整ったので機械学習入門するぞ