import ( "fmt" "github.com/docker/docker/cli/command" ) func main() { cli := command.NewDockerCli() configFile, err := cli.ConfigFile() if err != nil { fmt.Println(err) return } fmt.Println(configFile) }
import ( "fmt" "github.com/docker/docker/cli/command" "github.com/docker/docker/registry" ) func main() { cli := command.NewDockerCli() configFile, err := cli.ConfigFile() if err != nil { fmt.Println(err) return } cfg := configFile.Load() reg := registry.RegistryConfig{ IndexConfigs: map[string]registry.IndexInfo{ "my-registry": { Mirrors: []string{ "https://my-registry.com", }, }, }, } cfg.AuthConfigs["my-registry"] = reg configFile.Save(cfg) }This code creates a new `DockerCli` instance, retrieves the Docker configuration file using `DockerCli.ConfigFile`, adds a new registry configuration to the configuration file, and saves the updated configuration to disk.