编辑dockerfile
FROM ubuntu
CMD ["/bin/bash"]
RUN echo 'Asia/Shanghai' > /etc/timezone
RUN sed -i 's@//.*archive.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN sed -i 's@//ports.ubuntu.com@//mirrors.ustc.edu.cn@g' /etc/apt/sources.list
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -y \
&& apt-get install -y python-is-python3 python3-pip python3-numpy nano sudo \
&& apt clean -y \
&& rm -rf /var/lib/apt/lists/*
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
RUN pip install jupyter
RUN useradd -d /home/jupyter -u 1026 -g 100 -m jupyter
RUN chown -R jupyter /home/jupyter
RUN echo 'jupyter ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/jupyter
USER jupyter
WORKDIR /home/jupyter
RUN mkdir /home/jupyter/.jupyter
RUN mkdir /home/jupyter/.local
RUN pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple
ENTRYPOINT ["/bin/sh","-c","jupyter notebook"]
根据dockerfile编译镜像
docker build -t "ubuntu/jupyter" ./
编辑配置文件 jupyter_notebook_config.py
c = get_config()
c.NotebookApp.allow_remote_access = True
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.port = 8888
c.NotebookApp.notebook_dir = '/jupyter'
c.NotebookApp.open_browser = False
c.NotebookApp.terminado_settings={'shell_command':['/bin/bash']}
c.NotebookApp.iopub_msg_rate_limit=2147483647
c.NotebookApp.rate_limit_window=10.0
临时运行docker设置登录密码并提取文件 jupyter_notebook_config.json
docker run -it --rm --name jupyter_test \
-v $PWD:/jupyter \
--entrypoint sh \
ubuntu/jupyter \
-c "jupyter notebook password && cp /home/jupyter/.jupyter/jupyter_notebook_config.json /jupyter"
运行
docker run -itd --name jupyter --restart=unless-stopped -p 8888:8888 \
-v $PWD:/jupyter \
-v $PWD/config/jupyter_notebook_config.py:/home/jupyter/.jupyter/jupyter_notebook_config.py \
-v $PWD/config/jupyter_notebook_config.json:/home/jupyter/.jupyter/jupyter_notebook_config.json \
ubuntu/jupyter
解释
不知道为啥,群晖创建的默认用户的id是1026,群组id是100
-it 不知道什么意思
-d 后台运行
--name jupyter 创建jupyter得容器
--restart=unless-stopped 自启选项,这个是如果手动结束了容器那么就不会自启
-p 8888:8888 映射端口,与c.NotebookApp.port对应
-v $PWD:/jupyter 映射当前文件夹为容器里的/jupyter,与c.NotebookApp.notebook_dir对应
-v $PWD/config/jupyter_notebook_config.py:/home/jupyter/.jupyter/jupyter_notebook_config.py 映射配置文件
-v $PWD/config/jupyter_notebook_config.json:/home/jupyter/.jupyter/jupyter_notebook_config.json 映射配置文件
ubuntu/jupyter 镜像id