简体   繁体   English

如何将卷安装在由另一个Docker容器创建的Docker容器上?

[英]How do I mount volumes on a docker container that is being created by another docker container?

I have a containerized REST API server using docker. 我有一个使用docker的容器化REST API服务器。 I have mounted a folder on my host machine to this rest container using docker flag 我已经使用docker标志将主机上的文件夹安装到了该其余容器
--mount type=bind, source=<path/on/hostmachine>, target=<path/on/container>

This works perfectly and I can see real time mapping of files between my host and rest container. 这完美地工作了,我可以看到主机和rest容器之间文件的实时映射。 Now, my rest container generates a yaml file that contains the configuration for the new container that comes up and writes this configuration file to the shared volume mount. 现在,我的rest容器将生成一个yaml文件,其中包含要出现的新容器的配置,并将此配置文件写入共享卷装载。

I want to mount the same <path/on/hostmachine> that contains the configuration files generated by the rest container to the new container that comes up. 我想将包含由rest容器生成的配置文件的同一<path/on/hostmachine>挂载到出现的新容器中。 The issue is, I do not bring the container up using the cli. 问题是,我不使用cli来启动容器。

This is why I cannot use the --mount flag. 这就是为什么我不能使用--mount标志的原因。 I tried multiple ways to try doing it through the yaml file. 我尝试了多种方法来尝试通过yaml文件进行操作。

Blockquote - Using absolute path as Blockquote-使用绝对路径作为
volumes: - <absolute/path/on/hostmachine>:<path/on/new/container>

did not work. 不工作。

Blockquote - Using volumes with type defined as 块引用-使用类型定义为的卷
volumes: - type: bind source:<absolute/path/on/hostmachine> target:<path/on/new/container>

did not work and gave volumes should be string error 没用,给卷应该是字符串错误

How do I mount the same home directory to the new container that comes up on the rest container? 如何将相同的主目录安装到其余容器上出现的新容器?

I figured out the issue in the first approach. 我在第一种方法中发现了问题。 I was using my path as "./Users/username/Desktop" instead of "/Users/username/Desktop" which was causing the path mismatch. 我将路径用作“ ./Users/username/Desktop”,而不是“ / Users / username / Desktop”,这导致了路径不匹配。 I misunderstood the lack of errors. 我误解了缺少错误。 Rookie Mistake, Mea Culpa. 新秀错误,Mea Culpa。

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

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