HPCメモ

HPC(High Performance Computing)に関連したりしなかったりすることのメモ書き

M1 macでdocker

最近知ったんですが、M1 macでdockerのプレビュー版が動作するらしいです。

docs.docker.com

は?

たかがコンテナごときがなんでCPUアーキテクチャの違いを乗り越えて仮想化されてんだ?

と思ったんですが、良く考えたら元々Mac版はホストのkernel使ってなかったし、Rosetta2がなんとかしてくれるんしょうかね。

Don't think. Use! というわけでとりあえずインストールしてみました。

dmgファイルは冒頭のドキュメントの中程にある"Download"というリンクから入手できます。でもってインストーラが起動すると、これでもかとPreview版であることを強調してきますw

f:id:n_so5:20210215234232p:plain

いつもどおりにdrag and dropでインストールして起動すると、権限くれと言われるので

f:id:n_so5:20210215234831p:plain

パスワードを入力すると、チュートリアルが表示されました!

f:id:n_so5:20210215234957p:plain

って、何コレ???

結構長い間docker on macは使ってるはずですが、初めて見た気がします。普段は、homebrewからインストールしてたから見たことなかっただけかもしれませんが・・・

チュートリアルの内容は

  1. docker runでgitコマンドを呼び出して、チュートリアル用のgitリポジトリをclone
  2. cloneしてきたリポジトリ内にあるDockerfileを使ってdocker build
  3. buildしたimageを使って docker run
  4. Docker Hub でimageをshare

と、だいたい一通りの流れを体験できるようになっています。

最後のステップで、自然な流れでdockerhubのアカウントを作れるのが秀逸ですね。*1

なんか、この流れ見たことある気がするな・・・

ちなみにこのチュートリアルで使ったコンテナのDockerfileはこちらのものなので

github.com

(alpine-linuxだけど)pythonとnodeは動くようですね。あと、ビルド時にデフォルトでbuildkitが使われるようになってたようです。

さて、最後にjupyter-notebookのコンテナが動くかどうか確認して終わりにしましょう。

% docker run jupyter/scipy-notebook
Unable to find image 'jupyter/scipy-notebook:latest' locally
latest: Pulling from jupyter/scipy-notebook
83ee3a23efb7: Pull complete 
db98fc6f11f0: Pull complete 
f611acd52c6c: Pull complete 
724e03a65ce0: Pull complete 
513e138b0e94: Pull complete 
48f0bd4aefb5: Pull complete 
4f4fb700ef54: Pull complete 
b4de871b77c8: Pull complete 
0b03df09b2e6: Pull complete 
fa78867bfcd3: Pull complete 
47cf22ed95c5: Pull complete 
9ecce3ab59b4: Pull complete 
5ec66779f1e5: Pull complete 
cd7851ccfb49: Pull complete 
e80214e887dd: Pull complete 
b96af1630e18: Pull complete 
bec9edeb94f8: Pull complete 
dbb61cd8d6ce: Pull complete 
f880f4d488be: Pull complete 
6b4097a5c485: Pull complete 
c5dd0250935f: Pull complete 
f9c371873f19: Pull complete 
Digest: sha256:6cb01b1d6653efada4841bcad3a1f8e168e21dccc38dbd6fac7095208872c96f
Status: Downloaded newer image for jupyter/scipy-notebook:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice.
Executing the command: jupyter notebook
[I 15:20:08.305 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 2021-02-15 15:20:15.102 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-02-15 15:20:15.102 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-02-15 15:20:15.102 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-02-15 15:20:15.102 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2021-02-15 15:20:15.131 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab
[I 2021-02-15 15:20:15.131 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 15:20:15.146 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 15:20:15.146 NotebookApp] Jupyter Notebook 6.2.0 is running at:
[I 15:20:15.146 NotebookApp] http://229033e3a641:8888/?token=bee9c8c2b4937b43ac51edc40d12d39f75a28218708915be
[I 15:20:15.146 NotebookApp]  or http://127.0.0.1:8888/?token=bee9c8c2b4937b43ac51edc40d12d39f75a28218708915be
[I 15:20:15.147 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:20:15.161 NotebookApp] 
    
    To access the notebook, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/nbserver-9-open.html
    Or copy and paste one of these URLs:
        http://229033e3a641:8888/?token=bee9c8c2b4937b43ac51edc40d12d39f75a28218708915be
     or http://127.0.0.1:8888/?token=bee9c8c2b4937b43ac51edc40d12d39f75a28218708915be

最後に表示されてるURLにアクセスすると

f:id:n_so5:20210216002550p:plain

あ、ポートフォワード設定してないorz

-p 8888:8888 を追加して起動すると無事にjupyter-notebookの画面を拝むことができました。

f:id:n_so5:20210216003306p:plain

しょっちゅう起動/停止することを考えるとdocker-compose.ymlとか用意しといた方が良いんでしょうかね。

*1:既存ユーザは、メールアドレスではログインできない問題にはまりそうですがw