与Jupyter共享的Docker卷“锁”文件夹

发布于 2025-02-12 05:18:55 字数 583 浏览 1 评论 0原文

我正在Ubuntu上测试Docker Desktop 4.10 22.04。

假设我想运行jupyter笔记本:

docker run -it \
    -v "${PWD}":/home/jovyan/work \
    -p 8888:8888 \
    jupyter/base-notebook

通过这样做,我在尝试在“工作”目录中创建新笔记本时会遇到“允许拒绝”错误。

使用Chown选项启动笔记本,使我可以解决问题:

docker run -it \
    -v "${PWD}":/home/jovyan/work \
    -p 8888:8888 \
    --user root \
    -e CHOWN_HOME="yes" \
    -e CHOWN_HOME_OPTS="-R" \
    jupyter/base-notebook

此解决方案的缺点是更改文件夹的权限:我在文件夹上看到一个挂锁,即使删除了容器,也无法删除内容。特别是,所有者现在是“用户#100999”和组“ 100099”。

寻找替代解决方案对OS渗透没有影响。谢谢

I'm testing Docker Desktop 4.10 on Ubuntu 22.04.

Let's say that I want to run a Jupyter Notebook:

docker run -it \
    -v "${PWD}":/home/jovyan/work \
    -p 8888:8888 \
    jupyter/base-notebook

By doing so, I experience the "Permission denied" error while attempting to create a new notebook in the "work" directory.

Starting the notebook with chown options allows me to solve the problem:

docker run -it \
    -v "${PWD}":/home/jovyan/work \
    -p 8888:8888 \
    --user root \
    -e CHOWN_HOME="yes" \
    -e CHOWN_HOME_OPTS="-R" \
    jupyter/base-notebook

This solution has the drawback of changing the permissions of the folder: I see a padlock on the folder and cannot delete the contents, even after removing the container. In particular, Owner is now "user #100999" and Group "100099".

Looking for alternative solutions with no impact on os-permissions. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記柔刀 2025-02-19 05:18:55

您可以告诉Docker使用与已安装的目录相同的所有者和组。

docker run -it \
    -v "${PWD}":/home/jovyan/work \
    -p 8888:8888 \
    --user "$(stat -c '%u:%g' $PWD)" \
    --group-add users \
    jupyter/base-notebook

Stat命令用于检索当前目录所有者的用户ID和组ID。

You can tell Docker to use the same owner and group as the directory being mounted.

docker run -it \
    -v "${PWD}":/home/jovyan/work \
    -p 8888:8888 \
    --user "$(stat -c '%u:%g' $PWD)" \
    --group-add users \
    jupyter/base-notebook

The stat command is used to retrieve the user ID and group ID for the current directory's owner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文