英文:
How to debug docker-compose? Where are config paths set?
问题
我正在尝试调试docker-compose
,即这个Go文件,以解决一些问题(这个问题)。为了做到这一点,我已经设置了一个GoLang调试器。
go run main.go -f /.../project_root/docker-compose.yml -f /.../project_root/folder1/docker-compose.yml config
的输出结果如预期,即合并后的配置文件。
由于某种原因,我无法在代码中找到设置配置文件的地方,尽管它们必须在某个地方设置,因为输出结果是正确合并的配置文件。我怀疑它们可能在这里或这里附近设置。但在前一个位置,cli.configFile
的值为nil
,而在后一个位置,o.ConfigPaths
的值为nil
。
所以我有两个问题:
- 配置文件是在哪里设置的?
- (如果无法回答第一个问题)在尝试模拟实际的
docker-compose
命令行行为时,我做错了什么?
编辑
根据上述问题和已经找到配置路径可能被设置的位置,我现在的问题是卷路径是在哪里设置的。
英文:
I am trying to debug docker-compose
, i.e. this Go file, to work on some issue (this one). To do that, I have set up a GoLang debugger
The output of go run main.go -f /.../project_root/docker-compose.yml -f /.../project_root/folder1/docker-compose.yml config
is as expected, the merged config files.
For some reason, I can not find the config files being set in the code, although they must be set somewhere as the output is the correctly merged config files. I suspected they must be set somewhere around here or here. But in the former place, the value of cli.configFile
is nil
, and in the latter place, the value of o.ConfigPaths
is nil
.
So I have two questions:
- Where are the config files being set? and
- (if 1 cannot be answered) What am I doing wrong in trying to emulate the behavior of the actual
docker-compose
command?
Edit
In accordance to the above mentioned issue and having found where the config paths are probably set, my question now is where the volume paths are being set.
答案1
得分: 1
哪些配置路径?默认配置文件(docker-compose.yaml
)的路径由cli.WithDefaultConfigPath
方法设置(在compose-go
存储库中)。默认配置的可能名称在这里设置:
// DefaultFileNames定义了自动发现的Compose文件名称(按优先顺序)
var DefaultFileNames = []string{"compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml"}
WithDefaultConfigPath
方法遍历此列表,如果找到匹配的文件,则将其应用于ProjectOptions
结构体中的ConfigPaths
字段,在这里:
type ProjectOptions struct {
ProjectName string
Profiles []string
ConfigPaths []string
WorkDir string
ProjectDir string
EnvFile string
Compatibility bool
}
WithDefaultConfigPath
方法应用于toProjectOptions
方法中,在这里:
func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
return cli.NewProjectOptions(o.ConfigPaths,
append(po,
cli.WithWorkingDirectory(o.ProjectDir),
cli.WithOsEnv,
cli.WithEnvFile(o.EnvFile),
cli.WithDotEnv,
cli.WithConfigFileEnv,
cli.WithDefaultConfigPath,
cli.WithName(o.ProjectName))...)
}
英文:
Which config paths? The path for the default configuration file (docker-compose.yaml
) is set by the cli.WithDefaultConfigPath
method (in the compose-go
repository). The possible names for the default config are set here:
// DefaultFileNames defines the Compose file names for auto-discovery (in order of preference)
var DefaultFileNames = []string{"compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml"}
The WithDefaultConfigPath
method iterates over this list, and if it finds a matching file, it gets applied to the ConfigPaths
field in the ProjectOptions
struct, here:
type ProjectOptions struct {
ProjectName string
Profiles []string
ConfigPaths []string
WorkDir string
ProjectDir string
EnvFile string
Compatibility bool
}
The WithDefaultConfigPath
method is applied in the toProjectOptions
method, here:
func (o *ProjectOptions) toProjectOptions(po ...cli.ProjectOptionsFn) (*cli.ProjectOptions, error) {
return cli.NewProjectOptions(o.ConfigPaths,
append(po,
cli.WithWorkingDirectory(o.ProjectDir),
cli.WithOsEnv,
cli.WithEnvFile(o.EnvFile),
cli.WithDotEnv,
cli.WithConfigFileEnv,
cli.WithDefaultConfigPath,
cli.WithName(o.ProjectName))...)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论