-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading a Compose file results in undefined Labels #9808
Comments
My question is, how do you expect users to parse Docker-compose files? I might be using the wrong method |
I think your method is already right, even in the
|
Your code looks good to me given the behavior right now - that is the correct method to load projects 🙂 You're definitely not the first one to be tripped up by this, and we've discussed making some improvements here before, so I created compose-spec/compose-go#305 (the loading is actually handled by compose-spec/compose-go). I'm closing this issue, but please feel free to add your thoughts/input on the linked issue! |
Same as this previous PR, you should use the |
Thank you guys, I was just curious if there was another way already :) And yes @glours, forgot to use the AddLabel method, thanks for the reminder. |
For anyone new to this (like myself), when using the for serviceName, serviceConfig := range project.Services {
serviceConfig.CustomLabels =
serviceConfig.CustomLabels.
Add(api.ProjectLabel, project.Name).
Add(api.ServiceLabel, serviceConfig.Name).
Add(api.VersionLabel, api.ComposeVersion).
Add(api.WorkingDirLabel, project.WorkingDir).
Add(api.ConfigFilesLabel, strings.Join(project.ComposeFiles, ",")).
Add(api.OneoffLabel, "False")
project.Services[serviceName] = serviceConfig
} The reason for this can be found in the code of func (l Labels) Add(key, value string) Labels {
if l == nil {
l = Labels{}
}
l[key] = value
return l
} |
Description
Steps to reproduce the issue:
Describe the results you received:
If I comment the following lines of code:
I get the following error:
Describe the results you expected:
Not an error, an initialized custom labels string map
Additional information you deem important (e.g. issue happens only occasionally):
Output of
docker compose version
:github.com/docker/compose/v2 v2.10.2
Output of
docker info
:Additional environment details:
Related to:
#9579
And:
docker/roadmap#387
The text was updated successfully, but these errors were encountered: