github.phpd.cn/hashicorp/packer@v1.3.2/builder/docker/driver.go (about)

     1  package docker
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/hashicorp/go-version"
     7  )
     8  
     9  // Driver is the interface that has to be implemented to communicate with
    10  // Docker. The Driver interface also allows the steps to be tested since
    11  // a mock driver can be shimmed in.
    12  type Driver interface {
    13  	// Commit the container to a tag
    14  	Commit(id string, author string, changes []string, message string) (string, error)
    15  
    16  	// Delete an image that is imported into Docker
    17  	DeleteImage(id string) error
    18  
    19  	// Export exports the container with the given ID to the given writer.
    20  	Export(id string, dst io.Writer) error
    21  
    22  	// Import imports a container from a tar file
    23  	Import(path, repo string) (string, error)
    24  
    25  	// IPAddress returns the address of the container that can be used
    26  	// for external access.
    27  	IPAddress(id string) (string, error)
    28  
    29  	// Login. This will lock the driver from performing another Login
    30  	// until Logout is called. Therefore, any users MUST call Logout.
    31  	Login(repo, username, password string) error
    32  
    33  	// Logout. This can only be called if Login succeeded.
    34  	Logout(repo string) error
    35  
    36  	// Pull should pull down the given image.
    37  	Pull(image string) error
    38  
    39  	// Push pushes an image to a Docker index/registry.
    40  	Push(name string) error
    41  
    42  	// Save an image with the given ID to the given writer.
    43  	SaveImage(id string, dst io.Writer) error
    44  
    45  	// StartContainer starts a container and returns the ID for that container,
    46  	// along with a potential error.
    47  	StartContainer(*ContainerConfig) (string, error)
    48  
    49  	// StopContainer forcibly stops a container.
    50  	StopContainer(id string) error
    51  
    52  	// TagImage tags the image with the given ID
    53  	TagImage(id string, repo string, force bool) error
    54  
    55  	// Verify verifies that the driver can run
    56  	Verify() error
    57  
    58  	// Version reads the Docker version
    59  	Version() (*version.Version, error)
    60  }
    61  
    62  // ContainerConfig is the configuration used to start a container.
    63  type ContainerConfig struct {
    64  	Image      string
    65  	RunCommand []string
    66  	Volumes    map[string]string
    67  	Privileged bool
    68  }
    69  
    70  // This is the template that is used for the RunCommand in the ContainerConfig.
    71  type startContainerTemplate struct {
    72  	Image string
    73  }