简体   繁体   English

如何在 docker 中的 docker 中挂载文件?

[英]How to mount file inside docker in docker?

docker container start with docker 容器启动

- /var/run/docker.sock:/var/run/docker.sock

Inside docker container i want to call another docker something like this在 docker 容器内,我想调用另一个 docker 类似的东西

docker run --rm --net none -v /new/test.py:/new/test.py test-python timeout 5 make --silent -C /new/ test

but i get an error但我得到一个错误

docker: Error response from daemon: failed to create shim: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting to rootfs flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? docker:来自守护进程的错误响应:未能创建 shim:OCI 运行时创建失败:runc 创建失败:无法启动容器进程:容器初始化期间出错:错误安装到 rootfs 标志:0x5000:不是目录:未知:您是否尝试将目录挂载到文件上(反之亦然)? Check if the specified host path exists and is the expected type.检查指定的主机路径是否存在并且是预期的类型。

Without the -v parameter, the launch itself is processed如果没有 -v 参数,将处理启动本身

and When I call the same code not from the docker, everything works out当我从 docker 调用相同的代码时,一切正常

What could be the reason?可能是什么原因?

Remember, while you may have exposed the docker socket inside your container, the docker daemon is running on your host .请记住,虽然您可能已经暴露了容器内的 docker 套接字,但 docker 守护程序正在您的主机上运行 It's not inside any container.它不在任何容器内。 So when you write:所以当你写:

... -v /new/test.py:/new/test.py ...

Docker is looking for /new/test.py relative to the root of your host filesystem, not inside the container filesystem. Docker 正在寻找/new/test.py相对于您的主机文件系统的根目录,而不是在容器文件系统内。

In general, bind mounts aren't going to work in a useful fashion.一般来说,绑定挂载不会以有用的方式工作。 Named volumes will work fine, of course.当然,命名卷可以正常工作。

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

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