LoginSignup
7
5

More than 3 years have passed since last update.

Dockerで起動したJupyterLabでvimキーバインドを使う

Posted at

概要

前回Jupyter Notebookでvimのキーバインドが使えるようにしましたが、
JupyterLabの存在を完全に忘れていたので、、同様にDockerでJupyterLabを起動してvimのキーバインドが使えるようなやり方をまとめました。

参考:Dockerで起動したJupyter Notebookでvimキーバインドを使う

Jupyter NotebookとJupyterLabの違い

Jupyter notebookの後継機がJupyterLabになってまして、基本的に出来ることはどちらでも同じですが、JupyterLabの方が高機能になっています。
Jupyter notebookの開発は一旦終了して今後はJupyterLabに置き換わるようです。

環境

バージョン
Mac 10.15.3
Docker 19.03.4
docker-compose 1.24.1

環境構築手順

Dockerfileとdocker-composeを使ってvimのキーバインドが使えるJupyterLabを起動します。
※以下ファイルはGitHubにもまとめているのでご参考ください。
https://github.com/hikarut/Data-Science

1. notebook保存用のディレクトリ作成
$ mkdir notebooks
2. Dockerfileの作成
Dockerfile
FROM jupyter/datascience-notebook
USER root

RUN pip install jupyterlab==1.0
RUN jupyter serverextension enable --py jupyterlab
RUN jupyter labextension install jupyterlab_vim

EXPOSE 10000
CMD ["bash"]

jupyterlab_vimjupyterlab 1.0にしか対応してないようなのでバージョンを指定してインストールしてます
jupyterlab-vim:https://github.com/jwkvam/jupyterlab-vim

3. docker-compose.ymlの作成
docker-compose.yml
version: '3'
services:
  data-science:
    restart: always
    build: .
    container_name: 'data-science'
    ports:
      - "10000:10000"
    working_dir: '/root/'
    tty: true
    volumes:
        - ./notebooks:/root/notebooks/
4. コンテナのビルド
$ docker-compose up -d --build
5. コンテナにログイン
$ docker-compose exec data-science bash
6. Jupyter Notebookの起動
/root# jupyter lab --port 10000 --allow-root

表示されるhttp://127.0.0.1:10000/?token=xxxxxxxxxxxxxxxxにアクセスします。

Jupyter Notebookの時のように設定変更する必要もなく、そのままの状態でnotebook上でvimが使えるようになります
スクリーンショット 2020-02-17 22.34.20.png

最後に

JupyterLabの方がJupyter Notebookよりも気持ちセットアップが楽でした!
(今回もユーザーを全てrootにしちゃったのでその辺は変えた方が良いかもです。。。)
ただjupyterlab-vimのビルドがめちゃくちゃ遅いのが気になりましたが、、今後改善されると嬉しいなと思います。

参考
7
5
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
7
5