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之類的命令了。

相關文章
相關標籤/搜索