可以使用可变路径来挂载Docker吗,还是需要固定路径?

huangapple go评论63阅读模式
英文:

will it possible to make docker mount with variable path or fix path is required?

问题

目前,我正在为 Docker/容器挂载 HTTPS 证书,路径位于 Windows 机器上的 'C:\Users\user.aspnet'。

我想要更改位置,并希望将 HTTPS 证书 (https) 保存在源代码目录中。

对于用户 A,Base_Path = C:\Repos\app
对于用户 B,Base_Path = C:\Code\application\app,等等。

问题是,是否可能挂载满足所有用户的文件?还是我需要修复一个文件挂载路径(C:/https)?

英文:

Currently I am mounting https certificate for docker/container with below Windows machine path 'C:\Users\user.aspnet`.

volumes:
  - ~/.aspnet/https:/app/certs:ro

I want to change the location of and want to keep the https certificate (https) within the source code directory.

\\[Base_Path]\src\https

For user A, Base_Path = C:\Repos\app
For user B, Base_Path = C:\Code\application\app, etc.

Question is, will it be possible to mount the files which satisfy all the users? Or I need to fix a path for file mount (C:/https) ?

答案1

得分: 1

Compose volumes: 可以使用相对路径。路径相对于 docker-compose.yml 文件的位置来解释。如果您使用多个 docker-compose -f 选项,路径将相对于第一个 Compose 文件的位置来解释,即使该文件位于不同的目录中。

您描述的设置非常常见。根据我的经验,将绑定挂载的主机目录使用绝对路径实际上有点不寻常,因为不同的用户将具有不同的主目录,但受源代码控制的存储库的布局将在任何地方都相同。

英文:

Compose volumes: can use relative paths. The path is interpreted relative to the location of the docker-compose.yml file. If you use multiple docker-compose -f options, the path is interpreted relative to the location of the first Compose file, even if this one is in a different directory.

The setup you describe is quite common. IME it's actually a little unusual to use an absolute path as the host directory for a bind mount, exactly because different users will have different home directories but the layout of the source-controlled repository will be the same everywhere.

huangapple
  • 本文由 发表于 2023年7月10日 20:16:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76653645.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定