SIMULATAN
SIMULATAN

Reputation: 959

Call Docker-Compose commands in Go

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

Upvotes: 4

Views: 2275

Answers (1)

Kirill Scherba
Kirill Scherba

Reputation: 51

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)
}

Upvotes: 1

Related Questions