Jupyter notebook中的sudo问题详解

在Jupyter notebook的容器镜像栈中,使用了官方的jovyan帐号来进行默认登陆,该帐号没有root权限,不能执行apt之类的操做安装软件。这是为了保护本机宿主系统,但对于容器就很不方便,并且不是很必要(分使用场景哈)。html

开启root权限有两种办法:docker

  • 以root帐户运行notebook。
  • 设置jovyan的root权限。

基本用法:bash

docker run -p 8888:8888 -d --name jupyter jupyter/all-spark-notebook jupyter lab

一、以root帐户运行notebook

容器启动参数

Password authentication is disabled for the NB_USER (e.g., jovyan). This choice was made to avoid distributing images with a weak default password that users ~might~ will forget to change before running a container on a publicly accessible host.app

You can grant the within-container NB_USER passwordless sudo access by adding -e GRANT_SUDO=yes and --user root to your Docker command line or appropriate container orchestrator config.less

For example:spa

docker run -it -e GRANT_SUDO=yes --user root jupyter/minimal-notebook

改变配置参数

这个须要进容器去改变设置,而后重启。code

jupyter notebook --generate-config --allow-root

建议使用docker commit保存为新的镜像,而后从新运行docker服务。htm

二、设置jovyan的sudo权限

root进容器:get

docker exec -u 0 -it mycontainer bash

设置jovyan密码:it

passwd jovyan

加入sudoers清单:

visudo

加入:

jovyan ALL=(ALL:ALL) ALL

而后到notebook界面,就能够执行sudo apt update之类的命令了。

相关文章
相关标签/搜索