Deep Karmaning

技術系の話から日常のことまで色々と書きます

DockerでUbuntuにjupyterが入ったDockerfileを作ってみる

概要

※2019/5/29追記

githubの方にDockerfileを用意していますのでよかったらこちらも参考にどうぞ(スターつけてくれると嬉しいです)

github.com

(追記終わり)

前回はCentOSにRstudioを入れましたが、今回はUbuntuにjupyterを入れるDockerfileを作ってみます。

rf00.hatenablog.com

実装

Dockerfileは以下のように実装。

FROM ubuntu:18.04

#set up timezone
#https://sleepless-se.net/2018/07/31/docker-build-tzdata-ubuntu/
RUN DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y tzdata
# timezone setting
ENV TZ=Asia/Tokyo

#print command
RUN set -x

#install utility command
RUN apt-get update && \
    apt-get install -y --no-install-recommends wget sudo software-properties-common build-essential

#install jupyter
#https://daichan.club/linux/78323
RUN sudo apt-get update && \
    mkdir downloads && \
    wget -q https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh -P ./downloads/ && \
    bash ./downloads/Anaconda3-2018.12-Linux-x86_64.sh -b
ENV PATH $PATH:/root/anaconda3/bin
#setup jupyter
RUN jupyter notebook --generate-config && \
    sed -i -e "s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '0.0.0.0'/" /root/.jupyter/jupyter_notebook_config.py && \
    sed -i -e "s/#c.NotebookApp.allow_remote_access = False/c.NotebookApp.allow_remote_access = True/" /root/.jupyter/jupyter_notebook_config.py

#install packages
RUN conda install -y -c conda-forge pystan

EXPOSE 8888

dockerfileのあるフォルダで以下コマンド実行し、imageを作ります。

docker build -t jupyter .

そして、コンテナに入り、

docker run -it --name jupyter -p 8888:8888 jupyter /bin/bash

jupyterを立ち上げ、

jupyter notebook --allow-root

http://localhost:8888 にアクセスすると、以下の画面が出るので、

f:id:rf00:20190103180345p:plain

コマンドライン上に以下のように表示されているはずの、

To access the notebook, open this file in a browser:
        file:///root/.local/share/jupyter/runtime/nbserver-10-open.html
    Or copy and paste one of these URLs:
        http://(bc0ee4350825 or 127.0.0.1):8888/?token={ここにtokenが表示される}

tokenを入力します。

するとログインができるのであとはコードを書くだけです。

まとめ

とりあえず、素のUbuntuにjupyterを入れて立ち上げるところまではいけました。

次は諸々のパッケージ類を入れて、dockerfileを整理したリポジトリを作りたいと思います。