From 93b7643e3b15a484cf39f37dd584701b82cd076e Mon Sep 17 00:00:00 2001 From: Starlight-0208 <89368027+Starlight0208@users.noreply.github.com> Date: Tue, 22 Aug 2023 15:37:10 +0800 Subject: [PATCH] Added some Dockerfiles optimized the directory structure --- Dockerfile => Jupyter Lab/Dockerfile | 19 ++++++++------- Jupyter Notebook/Alpine-NonRoot/Dockerfile | 28 ++++++++++++++++++++++ Jupyter Notebook/Alpine-Root/Dockerfile | 20 ++++++++++++++++ README | 11 ++++++++- 4 files changed, 69 insertions(+), 9 deletions(-) rename Dockerfile => Jupyter Lab/Dockerfile (53%) create mode 100644 Jupyter Notebook/Alpine-NonRoot/Dockerfile create mode 100644 Jupyter Notebook/Alpine-Root/Dockerfile diff --git a/Dockerfile b/Jupyter Lab/Dockerfile similarity index 53% rename from Dockerfile rename to Jupyter Lab/Dockerfile index 2712b99..bad6d00 100644 --- a/Dockerfile +++ b/Jupyter Lab/Dockerfile @@ -1,14 +1,17 @@ FROM ubuntu:22.04 + RUN cp /etc/apt/sources.list /etc/apt/sources.list.ori && \ sed -i s@/archive.ubuntu.com/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.list && \ sed -i s@/security.ubuntu.com/@/mirrors.ustc.edu.cn/@g /etc/apt/sources.list && \ - apt clean + apt clean &&\ + mkdir /jupyter &&\ + groupadd notebook &&\ + useradd -m -s /bin/bash -G notebook notebooks &&\ + usermod -aG sudo notebooks &&\ + chown -R notebooks:notebook /jupyter RUN apt update && apt install -y python3 python3-pip -RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter -RUN jupyter notebook --generate-config -RUN apt install -y wget -RUN rm /root/.jupyter/jupyter_notebook_config.py && mkdir /jupyter -WORKDIR /root/.jupyter/ -RUN wget http://www.americas.asia/cdn/docker/jupyter/jupyter_notebook_config.py -O ./jupyter_notebook_config.py +RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyterlab + EXPOSE 8888 -CMD ["jupyter", "notebook", "--allow-root"] \ No newline at end of file +USER notebooks +CMD ["jupyter", "lab", "--no-browser", "--ip", "\"0.0.0.0\"", "--port", "8888", "--allow-root"] \ No newline at end of file diff --git a/Jupyter Notebook/Alpine-NonRoot/Dockerfile b/Jupyter Notebook/Alpine-NonRoot/Dockerfile new file mode 100644 index 0000000..2ec01f8 --- /dev/null +++ b/Jupyter Notebook/Alpine-NonRoot/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3-alpine + +LABEL maintainer="" +LABEL version="selfbuilt" + +WORKDIR /jupyter +RUN \ + sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories &&\ + apk add --no-cache libc-dev libffi-dev gcc && \ + pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter --no-cache-dir && \ + apk del libc-dev libffi-dev gcc &&\ + addgroup notebook &&\ + adduser -Ss /bin/nologin -g notebook notebook &&\ + chown -R notebook:notebook . &&\ + mkdir /data &&\ + chown -R notebook:notebook /data +RUN \ + jupyter notebook --generate-config &&\ + mkdir ./config &&\ + cp /root/.jupyter/jupyter_notebook_config.py ./config + +RUN \ + sed -i.bak 's/# c.NotebookApp.ip = .*/c.NotebookApp.ip = '\''0.0.0.0'\''/' ~/.jupyter/jupyter_notebook_config.py && \ + sed -i.bak 's/# c.NotebookApp.notebook_dir = .*/c.NotebookApp.notebook_dir = '\''\/data'\''/' ~/.jupyter/jupyter_notebook_config.py + +EXPOSE 8888 +USER notebook +CMD [ "jupyter", "notebook", "--config=", "\"/jupyter/config\"" ] \ No newline at end of file diff --git a/Jupyter Notebook/Alpine-Root/Dockerfile b/Jupyter Notebook/Alpine-Root/Dockerfile new file mode 100644 index 0000000..7e9dbce --- /dev/null +++ b/Jupyter Notebook/Alpine-Root/Dockerfile @@ -0,0 +1,20 @@ +FROM python:3-alpine + +LABEL maintainer="" +LABEL version="selfbuilt" + +WORKDIR /jupyter +RUN \ + sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories &&\ + apk add --no-cache libc-dev libffi-dev gcc && \ + pip install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter --no-cache-dir && \ + apk del libc-dev libffi-dev gcc +RUN \ + jupyter notebook --generate-config &&\ + mkdir /data &&\ + sed -i.bak 's/# c.NotebookApp.ip = .*/c.NotebookApp.ip = '\''0.0.0.0'\''/' /root/.jupyter/jupyter_notebook_config.py && \ + sed -i.bak 's/# c.NotebookApp.notebook_dir = .*/c.NotebookApp.notebook_dir = '\''\/data'\''/' /root/.jupyter/jupyter_notebook_config.py + +EXPOSE 8888 +USER root +CMD [ "jupyter", "notebook", "--allow-root" ] \ No newline at end of file diff --git a/README b/README index c7eeb9b..6302e4b 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ +Before building the image, please switch the working directory to the directory where the corresponding version Dockerfile resides build image by shell: docker build -t /jupyter: @@ -7,4 +8,12 @@ docker volume create jupyter docker run -itd --name jupyter -p 8888:8888 -v jupyter:/jupyter /jupyter: - Second Method -docker run -itd --name jupyter -p 8888:8888 -v /path/to/save:/jupyter /jupyter: \ No newline at end of file +docker run -itd --name jupyter -p 8888:8888 -v /path/to/save:/jupyter /jupyter: + +Version +------ +Jupyter Lab: + - / : Jupyter Lab servers built on Ubuntu, run as non-root users. +Jupyter Notebook: + - /Alpine-NonRoot : Jupyter Notebook server built on Alpine Linux, running with non-root users (`notebook`), this build is relatively secure. + - /Alpine-Root : Jupyter Notebook server built on Alpine Linux, running as Root user, this build is recommended only for testing or learning environments deployed on an Intranet. \ No newline at end of file