docker.go 446 B

12345678910111213141516171819202122
  1. package docker
  2. import (
  3. "context"
  4. "github.com/docker/docker/client"
  5. )
  6. // Initialize Docker client from environment variables
  7. func initClient() (cli *client.Client, err error) {
  8. cli, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
  9. if err != nil {
  10. return
  11. }
  12. // Optionally ping the server to ensure the connection is valid
  13. _, err = cli.Ping(context.Background())
  14. if err != nil {
  15. return
  16. }
  17. return
  18. }