在docker里使用jupyterhub

准备工作

需要先安装docker,具体方法参考我的上一篇文章。

1. 查看本地镜像docker images

D:\go 练习\go-zero-demo>docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
alpine/git    latest    c6b70534b534   3 months ago   27.4MB
hello-world   latest    feb5d9fea6a5   5 months ago   13.3kB

2. 在cmd里输入:docker search jupyterhub,查看docker hub上相关的镜像文件

D:\go 练习\go-zero-demo>docker search jupyterhub
NAME                                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
jupyterhub/jupyterhub                              JupyterHub: multi-user Jupyter notebook serv…   305                  [OK]
jupyterhub/singleuser                              single-user docker images for use with Jupyt…   42                   [OK]
jupyterhub/k8s-hub                                                                                 17
jupyterhub/k8s-singleuser-sample                                                                   8
bitnami/jupyterhub                                                                                 8
jupyterhub/jupyterhub-onbuild                      onbuild version of JupyterHub images            6
jupyterhub/configurable-http-proxy                 node-http-proxy + REST API                      5                    [OK]
jupyterhub/systemuser                              system-user image for use with JupyterHub an…   3                    [OK]
jupyterhub/k8s-binderhub                                                                           3
labshare/jupyterhub                                JupyterHub server for Kubernetes with OAuth …   3
jupyterhub/k8s-image-awaiter                                                                       1
jupyterhub/k8s-secret-sync                                                                         1
jupyterhub/k8s-pod-culler                                                                          1
jupyterhub/k8s-image-cleaner                                                                       1
jupyterhub/k8s-pre-puller                                                                          1
jupyterhub/k8s-network-tools                                                                       1
jupyterhub/jupyterhub-demo                                                                         0
pachyderm/jupyterhub-pachyderm-user                                                                0
jupyterhub/mybinder.org-tc-init                                                                    0
pachyderm/jupyterhub-pachyderm-hub                                                                 0
jupyterhub/mybinder.org-federation-redirect                                                        0
jupyterhub/mybinder.org-minesweeper                                                                0
jupyterhub/mybinder.org-proxy-patches                                                              0
jupyterhub/mybinder.org-analytics-publisher                                                        0
jupyterhub/binderhub-ci-repos_minimal-dockerfile   The minimal Dockerfile that would work with …   0

3. 拉取镜像文件docker pull jupyterhub

D:\go 练习\go-zero-demo>docker pull jupyterhub/jupyterhub
Using default tag: latest
latest: Pulling from jupyterhub/jupyterhub
54ee1f796a1e: Pull complete
f7bfea53ad12: Pull complete
46d371e02073: Pull complete
b66c17bbf772: Pull complete
44bfe3e8a19f: Pull complete
272415e84c73: Pull complete
6ae28b16fe2b: Pull complete
b9e74140c7b6: Pull complete
7ee24536bcb0: Pull complete
29d58fb561ea: Pull complete
ab11d07d88fe: Pull complete
Digest: sha256:678b508405f938a1564a81f2d4327ada0b079452ede5a7e57ae358f88fe27a3b
Status: Downloaded newer image for jupyterhub/jupyterhub:latest
docker.io/jupyterhub/jupyterhub:latest

4. 查看本地镜像docker images

D:\go 练习\go-zero-demo>docker images
REPOSITORY              TAG       IMAGE ID       CREATED        SIZE
jupyterhub/jupyterhub   latest    1cd4fbaf4648   4 weeks ago    355MB
alpine/git              latest    c6b70534b534   3 months ago   27.4MB
hello-world             latest    feb5d9fea6a5   5 months ago   13.3kB

5. 运行一个jupyterhub容器 ,docker run jupyterhub/jupyterhub

D:\go 练习\go-zero-demo>docker run jupyterhub/jupyterhub
[I 2022-02-28 01:57:11.863 JupyterHub app:2766] Running JupyterHub version 2.1.1
[I 2022-02-28 01:57:11.864 JupyterHub app:2796] Using Authenticator: jupyterhub.auth.PAMAuthenticator-2.1.1
[I 2022-02-28 01:57:11.864 JupyterHub app:2796] Using Spawner: jupyterhub.spawner.LocalProcessSpawner-2.1.1
[I 2022-02-28 01:57:11.864 JupyterHub app:2796] Using Proxy: jupyterhub.proxy.ConfigurableHTTPProxy-2.1.1
[I 2022-02-28 01:57:11.871 JupyterHub app:1651] Writing cookie_secret to /srv/jupyterhub/jupyterhub_cookie_secret
[I 2022-02-28 01:57:11.888 alembic.runtime.migration migration:201] Context impl SQLiteImpl.
[I 2022-02-28 01:57:11.889 alembic.runtime.migration migration:204] Will assume non-transactional DDL.
[I 2022-02-28 01:57:11.905 alembic.runtime.migration migration:615] Running stamp_revision  -> 833da8570507
[I 2022-02-28 01:57:12.022 JupyterHub proxy:496] Generating new CONFIGPROXY_AUTH_TOKEN
[I 2022-02-28 01:57:12.049 JupyterHub app:1924] Not using allowed_users. Any authenticated user will be allowed.
[I 2022-02-28 01:57:12.073 JupyterHub app:2835] Initialized 0 spawners in 0.003 seconds
[W 2022-02-28 01:57:12.075 JupyterHub proxy:687] Running JupyterHub without SSL.  I hope there is SSL termination happening somewhere else...
[I 2022-02-28 01:57:12.075 JupyterHub proxy:691] Starting proxy @ http://:8000
01:57:12.543 [ConfigProxy] info: Proxying http://*:8000 to (no default)
01:57:12.545 [ConfigProxy] info: Proxy API at http://127.0.0.1:8001/api/routes
01:57:13.051 [ConfigProxy] info: 200 GET /api/routes
[I 2022-02-28 01:57:13.052 JupyterHub app:3084] Hub API listening on http://127.0.0.1:8081/hub/
01:57:13.053 [ConfigProxy] info: 200 GET /api/routes
[I 2022-02-28 01:57:13.053 JupyterHub proxy:431] Adding route for Hub: / => http://127.0.0.1:8081
01:57:13.054 [ConfigProxy] info: Adding route / -> http://127.0.0.1:8081
01:57:13.054 [ConfigProxy] info: Route added / -> http://127.0.0.1:8081
01:57:13.055 [ConfigProxy] info: 201 POST /api/routes/
[I 2022-02-28 01:57:13.055 JupyterHub app:3150] JupyterHub is now running at http://:8000

6. 也可以使用后台运行方式,运行一个jupyterhub的容器:docker run -d -p 8000:8000 jupyterhub/jupyterhub

效果如下:

C:\Users\Carino>docker run -d -p 8000:8000 jupyterhub/jupyterhub
11917ae11faddba68423bfee57272593e3b7b0dd9a29adb712454d983faea2bc

查询运行容器的端口号docker ps:

C:\Users\Carino>docker ps
CONTAINER ID   IMAGE                   COMMAND        CREATED         STATUS         PORTS                    NAMES
11917ae11fad   jupyterhub/jupyterhub   "jupyterhub"   2 minutes ago   Up 2 minutes   0.0.0.0:8000->8000/tcp   nostalgic_jemison

在浏览器里输入```localhost:8000`访问服务:
在docker里使用jupyterhub_第1张图片
此时没有注册用户,所以没法登录。

7. 创建用户并登录

重新打开一个CMD窗口,输入docker exec -it 11917ae11fad /bin/bash或者docker exec -it jupyterhub bash进入正在运行的jupyterhub容器:

C:\Users\Carino>docker exec -it 11917ae11fad /bin/bash
root@11917ae11fad:/srv/jupyterhub#

这是一个Linux环境,在这个terminal里输入:adduser user -p 123456,创建一个用户user,密码123456
用这个用户密码登录刚刚的登录界面,即可登入:
在docker里使用jupyterhub_第2张图片
不知道什么原因,服务没有启动成功:
在docker里使用jupyterhub_第3张图片

----------------------------------------------持续更新中--------------------------------------

其他

查看所有容器docker ps -a

参数, -i:交互式,-t:终端,-d:后台运行,-P:将容器内部使用的网络端口随机映射到我们使用的主机上。

停止容器docker stop <容器 ID>

进入后台运行容器docker attach <容器 ID>

退出但不停止容器运行docker exec <容器 ID>

删除容器docker rm <容器 ID>

你可能感兴趣的:(docker,容器,kubernetes)