backend.go 744 B

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