LoginSignup
2
1

More than 3 years have passed since last update.

Docker for Windowsでconda createする

Last updated at Posted at 2019-06-23

(自分用メモに作ったmarkdownをうっかり消す可能性があるので、Qiitaへ公開します。)

DockerのWindows10での使い方

そもそも

そもそも論としてWindows ProでないとHyper-Vを有効化できない。Hyper-VはDocker起動に必須の仮想化技術のことを指す。そのため、DockerのためにはWindows Proを開いていることが事前条件となる。

なお、本稿ではDocker for Windowsをインストールしている前提で話を進めます。他の記事をご参照ください。

手順

以下でdockerで始まるコマンドは全てWindows Powershell上で実行します。涙が出そう。

  1. OSの鋳型(image)を取ってくる: e.g. docker pull ubuntu:latest, docker pull continuumio/miniconda
  2. マウント(-vオプション)する場合には、Docker for Windowsを開いてディスクを共有可能にしておくc.f. Qiita記事
  3. OSの複製を作る/OSを具体化する(コンテナを作る): docker run --name paul -v c:/host/machine/path:/NEW_OS_LOCATION -it continuumio/miniconda /bin/bash
    1. --network hostをつけないとVMから外へ、特にSSL通信ができないので注意。
  4. コンテナを起動する: docker start paul
  5. 適宜コマンドを実行: docker exec -ti paul /bin/bash, docker exec -ti paul sh -c "echo brabrabgrabar"
  6. 全作業が終わったら...
    1. とりあえずコンテナを停止する: docker stop paul
    2. コンテナを消すことも可能: docker rm paul
使用例
docker run --name signac -v d:/pythonprojects/doc2vec:/data -it continuumio/miniconda /bin/bash
docker start signac
docker exec -ti signac sh -c "echo aaaaaaaaaaaaaa"
docker exec -ti signac sh -c "conda env create -f /data/environment.yml"

continuumio/miniconda補足

vimviコマンドがありません。デフォルトで~/.bashrcの中にsource activate baseが書いてあります。編集できない場合はsed -i -e 's/base/YOUR_CONDA_ENV_NAME/g' ~/.bashrcなどと実行すれば大丈夫です。

Command and Error Message

conda create が弾かれる場合があります。いろいろ調べましたが、port-forwardの設定かと思いきや、使用しているWi-Fiネットワークがproxy設定を必要とするから、というのが原因でした。

本当はproxy設定を調べてdockerに認識させるべきです。悪手として、フリーWi-Fiに繋ぐという対応があります(proxy周りをまだ理解していないため)。

うまくいかない
docker exec -ti signac sh -c "conda env create -f /data/environment.yml"
Collecting package metadata: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/linux-64/repodata.json.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.

ConnectionError(MaxRetryError("HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/linux-64/repodata.json.bz2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7fc2d4784210>: Failed to establish a new connection: [Errno 111] Connection refused',))",),)
2
1
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
2
1