英文:
Call Docker-Compose commands in Go
问题
我想用Go语言编写一个CLI,为Docker-Compose提供一些便利功能,但不幸的是,我找不到与API相关的文档。我在代码库中进行了搜索,但代码结构相当复杂,我无法深入了解。目前,我唯一的选择似乎是使用shell执行命令。
我目前最好的猜测是直接调用(*github.com/docker/compose/pkg/api.ServiceProxy).RunOneOffContainer
,但我似乎无法弄清楚如何获取所有依赖项,如cli和context。
简而言之,我如何以编程方式调用docker-compose的命令,比如up
?
英文:
I want to make a CLI that provides some QoL Features for Docker-Compose in go, but unfortunately, I can't find any docs related to the API. I searched through the repo, but the codebase is quite nested and I can't get to the bottom of it. My only choice atm seems to just execute the commands using the shell..
My current best guess is to directly invoke (*github.com/docker/compose/pkg/api.ServiceProxy).RunOneOffContainer
but I can't seem to figure out how to get all the dependencies like the cli and context.
TL;DR: how do I programmatically call docker-compose commands like up
答案1
得分: 1
没有docker compose API。如果你选择使用shell执行docker-compose命令,那么在Go中使用'exec.Command':
out, err := exec.Command("docker", "compose", "up").Output()
if err != nil {
log.Fatal(err)
}
英文:
There is no docker compose API. If you choice execute the docker-compose commands using the shell, then use 'exec.Command' in Go:
out, err := exec.Command("docker", "compose", "up").Output()
if err != nil {
log.Fatal(err)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论