简体   繁体   English

在jupyter dockerfile中创建非root用户

[英]Creating non-root user in jupyter dockerfile

I am starting with docker and built an image with jupyter and some python libraries. 我从docker开始,并使用jupyter和一些python库构建了映像。 The end user should be able to use jupyter and access specific host data directories throught the container (read/write rights), but must be a non-root user. 最终用户应该能够使用jupyter并通过容器访问特定的主机数据目录(读/写权限),但最终用户必须是非root用户。 Here is my dockerfile so far: 到目前为止,这是我的dockerfile:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y \
python-pip

RUN pip install --upgrade pip && pip install jupyter \
pandas \
numpy

RUN useradd -r -g users A && \
mkdir /myhome && \
chown -R A:users /myhome

EXPOSE 8888

WORKDIR /myhome

CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=0.0.0.0"]

I run this by doing docker run -it -p 8888:8888 -u="A" -v /some/host/files:/myhome 我通过执行docker run -it -p 8888:8888 -u="A" -v /some/host/files:/myhome

But then I got a jupyter error that says OSError: [Errno 13] Permission denied: '/home/A' Any help appreciated. 但是然后我得到一个jupyter错误,提示OSError: [Errno 13] Permission denied: '/home/A'感谢任何帮助。 Many thanks! 非常感谢!

When you start your container with --entrypoint=bash, you will find that the home directory /home/A of your user has not been created. 当使用--entrypoint = bash启动容器时,您会发现尚未创建用户的主目录/ home / A。 To do that, you need to add the -m flag to the useradd command 为此,您需要将-m标志添加到useradd命令中

Some more info: You might want to take a look at the docker-stacks projects ( https://github.com/jupyter/docker-stacks/tree/master/base-notebook and derived images). 更多信息:您可能想看一下docker-stacks项目( https://github.com/jupyter/docker-stacks/tree/master/base-notebook和派生图像)。 That seems to match with what you're trying to do and adds some other helpful stuff. 这似乎与您要尝试执行的操作相匹配,并添加了一些其他有用的东西。 Eg when running a dockerized jupyter, you need a "PID 1 reaper"; 例如,运行dockerized jupyter时,您需要“ PID 1收割机”; otherwise your exited notebook kernels turn into zombies (you can google for that :-) 否则,您退出的笔记本内核会变成僵尸(您可以在Google上搜索它:-)

Also, when sharing host files with a non-root user inside the container, you will often need to set the UID of your container user to some specific value matching with the host system, so the file system permissions are properly matched. 另外,与容器内的非root用户共享主机文件时,通常需要将容器用户的UID设置为与主机系统匹配的某个特定值,以便正确匹配文件系统权限。 The docker-stacks containers support that too. docker-stacks容器也支持。 Their Dockerfiles might at least help as a boilerplate to run your own. 他们的Dockerfile至少可以帮助您运行自己的样板文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM