4

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

5
  • afaik there is no compose sdk. I have asked this in the slack channel some time back. Commented May 9, 2022 at 12:10
  • Well thats... sad, can I maybe do something with the compose spec (github.com/compose-spec/compose-go)? Commented May 9, 2022 at 12:11
  • I dont think its easy because its wrapped in a command line app. The linked repo is for working with compose files. Like parsing them and so on. Commented May 9, 2022 at 12:13
  • My idea was to maybe be able to use the compose-spec repo to parse the compose files into something that the Docker SDK can use Commented May 9, 2022 at 12:14
  • ...which is broadly what docker-compose does already. Commented May 9, 2022 at 13:26

1 Answer 1

1

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)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.