在Jupyter notebook的容器鏡像棧中,使用了官方的jovyan帳號來進行默認登陸,該帳號沒有root權限,不能執行apt之類的操做安裝軟件。這是爲了保護本機宿主系統,但對於容器就很不方便,並且不是很必要(分使用場景哈)。html
開啓root權限有兩種辦法:docker
基本用法:bash
docker run -p 8888:8888 -d --name jupyter jupyter/all-spark-notebook jupyter lab
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
root進容器:get
docker exec -u 0 -it mycontainer bash
設置jovyan密碼:it
passwd jovyan
加入sudoers清單:
visudo
加入:
jovyan ALL=(ALL:ALL) ALL
而後到notebook界面,就能夠執行sudo apt update之類的命令了。