backend.go 959 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package example
  2. import (
  3. "context"
  4. "fmt"
  5. "io"
  6. "github.com/docker/api/backend"
  7. "github.com/docker/api/containers"
  8. )
  9. type containerService struct{}
  10. func init() {
  11. backend.Register("example", "example", func(ctx context.Context) (interface{}, error) {
  12. return New(), nil
  13. })
  14. }
  15. func New() containers.ContainerService {
  16. return &containerService{}
  17. }
  18. func (cs *containerService) List(ctx context.Context) ([]containers.Container, error) {
  19. return []containers.Container{
  20. {
  21. ID: "id",
  22. Image: "nginx",
  23. },
  24. {
  25. ID: "1234",
  26. Image: "alpine",
  27. },
  28. }, nil
  29. }
  30. func (cs *containerService) Run(ctx context.Context, r containers.ContainerConfig) error {
  31. fmt.Printf("Running container %q with name %q\n", r.Image, r.ID)
  32. return nil
  33. }
  34. func (cs *containerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
  35. fmt.Printf("Executing command %q on container %q", command, name)
  36. return nil
  37. }