Jupyter Lab Docker 配置文件

Dockerfile_base

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FROM python:3.9

WORKDIR /usr/src/app

ENV LANG C.UTF-8
COPY requirements.txt .

RUN rm -f /etc/apt/sources.list \
&& echo "deb https://mirrors.tencent.com/debian/ bullseye main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb https://mirrors.tencent.com/debian-security/ bullseye-security main" >> /etc/apt/sources.list \
&& echo "deb https://mirrors.tencent.com/debian/ bullseye-updates main non-free contrib" >> /etc/apt/sources.list \
&& echo "deb https://mirrors.tencent.com/debian/ bullseye-backports main non-free contrib" >> /etc/apt/sources.list \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone \
&& apt update -y \
&& apt install -y wget curl git vim nodejs tree && apt clean \
&& mkdir /usr/src/app/workspace

RUN pip install -r requirements.txt -i https://pypi.doubanio.com/simple/ \
&& jupyter lab build

requirements.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
alembic==1.7.7
anyio==3.5.0
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.5
async-generator==1.10
attrs==21.4.0
Babel==2.9.1
backcall==0.2.0
beautifulsoup4==4.10.0
bleach==4.1.0
certifi==2021.10.8
certipy==0.1.3
cffi==1.15.0
charset-normalizer==2.0.12
colorama==0.4.4
cryptography==36.0.2
debugpy==1.6.0
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==0.8.3
fastjsonschema==2.15.3
gitdb==4.0.9
GitPython==3.1.27
greenlet==1.1.2
idna==3.3
ipykernel==6.9.2
ipython==8.1.1
ipython-genutils==0.2.0
ipywidgets==7.7.0
jedi==0.18.1
Jinja2==3.1.0
json5==0.9.6
jsonschema==4.4.0
jupyter==1.0.0
jupyter-client==7.1.2
jupyter-console==6.4.3
jupyter-core==4.9.2
jupyter-server==1.15.6
jupyter-server-mathjax==0.2.5
jupyter-telemetry==0.1.0
jupyterhub==2.2.2
jupyterlab==3.0.0
jupyterlab-git==0.36.0
jupyterlab-language-pack-zh-CN==3.3.post2
jupyterlab-pygments==0.1.2
jupyterlab-server==2.11.2
jupyterlab-widgets==1.1.0
Mako==1.2.0
MarkupSafe==2.1.1
matplotlib-inline==0.1.3
mistune==0.8.4
nbclassic==0.3.7
nbclient==0.5.13
nbconvert==6.4.4
nbdime==3.1.1
nbformat==5.2.0
nest-asyncio==1.5.4
notebook==6.4.10
notebook-shim==0.1.0
oauthlib==3.2.0
packaging==21.3
pamela==1.0.0
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
prometheus-client==0.13.1
prompt-toolkit==3.0.28
psutil==5.9.0
ptyprocess==0.7.0
pure-eval==0.2.2
pycparser==2.21
Pygments==2.11.2
pyOpenSSL==22.0.0
pyparsing==3.0.7
pyrsistent==0.18.1
python-dateutil==2.8.2
python-json-logger==2.0.2
pytz==2022.1
pyzmq==22.3.0
qtconsole==5.3.0
QtPy==2.0.1
requests==2.27.1
ruamel.yaml==0.17.21
ruamel.yaml.clib==0.2.6
Send2Trash==1.8.0
six==1.16.0
smmap==5.0.0
sniffio==1.2.0
soupsieve==2.3.1
SQLAlchemy==1.4.32
stack-data==0.2.0
terminado==0.13.3
testpath==0.6.0
tornado==6.1
traitlets==5.1.1
urllib3==1.26.9
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==1.3.1
widgetsnbextension==3.6.0

jupyter_server_config.py

1
2
3
4
5
6
7
# Configuration file for jupyter-notebook.

c.ServerApp.notebook_dir = '/usr/src/app/workspace'
c.ServerApp.open_browser = False
c.ServerApp.port = 8888
c.ServerApp.token = 'xxxxx'
c.ServerApp.ip = "*"

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
FROM jupyterlab:base    

COPY requirements_ifan.txt .
COPY jupyter_server_config.py /root/.jupyter/
COPY vimrc /root/.vimrc

SHELL ["/bin/bash", "-c"]

RUN python3 -m venv /usr/src/app/envs/ifan \
&& source /usr/src/app/envs/ifan/bin/activate \
&& pip install -r requirements_ifan.txt -i https://pypi.doubanio.com/simple/ \
&& python -m ipykernel install --user --name ifan --display-name "ifan" \
&& deactivate

CMD ["jupyter", "lab", "--allow-root"]

requirements_ifan.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
aiomysql==0.1.0
aliyun-python-sdk-core==2.13.36
aliyun-python-sdk-kms==2.15.0
anyio==3.5.0
APScheduler==3.9.1
asgiref==3.5.0
async-timeout==4.0.2
attrs==21.4.0
Automat==20.2.0
cachetools==5.0.0
certifi==2021.10.8
cffi==1.15.0
charset-normalizer==2.0.12
click==8.1.2
constantly==15.1.0
crcmod==1.7
cryptography==36.0.2
cssselect==1.1.0
DBUtils==3.0.2
Deprecated==1.2.13
Django==4.0.4
elasticsearch==5.3.0
fastapi==0.75.2
filelock==3.6.0
Flask==2.1.1
gevent==21.12.0
google-auth==2.6.5
greenlet==1.1.2
h11==0.12.0
hiredis==2.0.0
httpcore==0.14.7
httpx==0.22.0
hyperlink==21.0.0
idna==3.3
importlib-metadata==4.11.3
incremental==21.3.0
itemadapter==0.5.0
itemloaders==1.0.4
itsdangerous==2.1.2
Jinja2==3.1.1
jmespath==0.10.0
kubernetes==23.3.0
lxml==4.8.0
MarkupSafe==2.1.1
motor==2.5.1
numpy==1.22.3
oauthlib==3.2.0
oss2==2.15.0
packaging==21.3
pandas==1.4.2
parsel==1.6.0
Protego==0.2.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pycryptodome==3.14.1
pydantic==1.9.0
PyDispatcher==2.0.5
pymongo==3.12.3
PyMySQL==1.0.2
pyOpenSSL==22.0.0
pyparsing==3.0.8
python-dateutil==2.8.2
python-snappy==0.6.1
pytz==2022.1
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0
queuelib==1.6.2
redis==4.2.2
requests==2.27.1
requests-file==1.5.1
requests-oauthlib==1.3.1
rfc3986==1.5.0
rsa==4.8
Scrapy==2.6.1
service-identity==21.1.0
six==1.16.0
sniffio==1.2.0
SQLAlchemy==1.4.35
sqlparse==0.4.2
starlette==0.17.1
tldextract==3.2.1
tornado==6.1
Twisted==22.4.0
typing_extensions==4.2.0
tzdata==2022.1
tzlocal==4.2
urllib3==1.26.9
w3lib==1.22.0
websocket-client==1.3.2
Werkzeug==2.1.1
wrapt==1.14.0
zipp==3.8.0
zope.event==4.5.0
zope.interface==5.4.0
ipykernel

core.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
k8s-app: jupyterlab-ifan
name: jupyterlab-ifan
spec:
selector:
matchLabels:
k8s-app: jupyterlab-ifan
template:
metadata:
labels:
k8s-app: jupyterlab-ifan
spec:
containers:
- image: jupyterlab:ifan
imagePullPolicy: Always
name: jupyterlab-ifan
ports:
- containerPort: 8888
protocol: TCP
resources:
limits:
cpu: 500m
memory: 500Mi
requests:
cpu: 100m
memory: 300Mi
volumeMounts:
- mountPath: /usr/src/app/workspace/
subPath: jupyter-ifan/workspace/
name: jupyterlab-pvc
imagePullSecrets:
- name: rd
volumes:
- name: jupyterlab-pvc
persistentVolumeClaim:
claimName: jupyter-lab-ifan

---
apiVersion: v1
kind: Service
metadata:
name: jupyterlab-ifan
spec:
ports:
- nodePort: 32004
port: 80
protocol: TCP
targetPort: 8888
selector:
k8s-app: jupyterlab-ifan
sessionAffinity: None
type: NodePort

start.sh

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

DOCKER_HUB_IMAGE=jupyterlab:ifan

docker stop jupyterlab && docker rm jupyterlab
docker build . -t jupyterlab:base -f Dockerfile_base
docker build . -t jupyterlab -f Dockerfile
docker tag jupyterlab $DOCKER_HUB_IMAGE
docker push $DOCKER_HUB_IMAGE
#docker run -d --name jupyterlab -p 8888:8888 -v /workspace/jupyter:/usr/src/app/workspace jupyterlab
#docker logs -f jupyterlab