package main import ( "context" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" ) func main() { cli, _ := client.NewEnvClient() ctx := context.Background() resp, err := cli.ContainerCreate(ctx, &container.Config{ Image: "ubuntu", Cmd: []string{"ls", "/invalid/path"}, }, nil, nil, "") if err != nil { panic(err) } err = cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) if err != nil { panic(types.NewErrJob("Error starting container", err)) } }
package main import ( "context" "github.com/docker/docker/api/types" "github.com/docker/docker/client" "github.com/docker/docker/engine" ) func main() { cli, _ := client.NewEnvClient() ctx := context.Background() _, err := cli.Info(ctx) if err != nil { if je, ok := err.(engine.JobError); ok { // Handle JobError if je.Retriable { // Retry } else { // Log error and fail } } else { // Handle other errors } } }In both examples, we import the necessary package libraries and create a docker client. We then execute a job and catch any errors using the Job Error package from the docker engine library.