0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

jupyterのDockerfile

0
Last updated at Posted at 2024-06-16

ubuntu ベースでJupyterでnumpyやpandasなどを実行できる最低限の環境を作る。

特筆すべきことはあまりないが、pipでjupyterをシステムPythonに追加するとおこられるので --break-system-package フラグをつけて強行している。

CMD--allow-root をつけないと、ルートで起動できない。また --ip=0.0.0.0 をつけないとデフォルトでlocalhost しかlistenしないので、外部からアクセスできなくなる。

FROM ubuntu:latest

RUN apt update
RUN apt -y upgrade
RUN apt install -y tzdata
ENV TZ=Asia/Tokyo
RUN echo "$TZ" > /etc/timezone \
  && rm /etc/localtime \
  && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
  && dpkg-reconfigure -f noninteractive tzdata

RUN apt install -y python3 python3-pip
RUN apt install -y python3-numpy
RUN apt install -y python3-matplotlib
RUN apt install -y python3-pandas 

RUN pip3 install --break-system-package jupyter

CMD ["jupyter", "notebook", "--allow-root", "--ip=0.0.0.0"]

ビルド

ビルドはごく普通に行う。

> docker build -f Dockerfile . -t pythonenv   

起動

jupyter は普通ランダムに生成したトークンを画面に表示して起動し、それを入力しないとログインできないようになっている。パスワードを設定することもできるが、実は環境変数でトークンを外から与えられるようになっている。これを使うとDocker起動時にトークンを指定できる。

> docker run -p 8000:8888 -e JUPYTER_TOKEN="token" pythonenv

このようにして、ホストの8000にアクセスするとトークンを要求するプロンプトが出るので、起動時に指定したトークンtokenを入力すると、jupyterが使える。すばらしい。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?