Gocker is a CLI generator to create and execute Docker commands in Go.
To install Gocker, use go get
:
go get github.com/rojack96/gocker
Here is an example of how to use Gocker to execute a Docker Compose command:
package main
import (
"fmt"
"github.com/rojack96/gocker"
)
func main() {
compose := gocker.Compose()
result := compose.FileName("compose.yml").Up().Build().ServiceNames()
fmt.Println(result.GetCommand())
// output: "docker compose --file compose.yml up --build hello-world"
result.Exec(false)
}
Gocker supports Docker commands for version 26.1.3.
Currently, all compose
commands are implemented, and support for other Docker commands is coming soon.
// Create compose instance
compose := gocker.Compose()
result := compose.FileName("compose.yml"). //(optional) Docker file
Up(). // up command
Build(). // --build command
ServiceNames() // service name to start, if empty, all services will be started
fmt.Println(result.GetCommand())
// output: "docker compose --file compose.yml up --build hello-world"
// Create compose instance
compose := gocker.Compose()
result := compose.FileName("compose.yml"). // Docker file, if empty it will not be included
Up(). // up command
Build(). // --build command
ServiceNames() // service name to start, if empty, all services will be started
result.Exec(false) // if true, the command will be executed with administrator privileges
If you want to contribute to Gocker, feel free to do so! You can create a pull request or open an issue to discuss changes.
This project is licensed under the MIT License. See the LICENSE
file for more details.