本文整理匯總了Golang中github.com/fsouza/go-dockerclient.AttachToContainerOptions類的典型用法代碼示例。如果您正苦於以下問題:Golang AttachToContainerOptions類的具體用法?Golang AttachToContainerOptions怎麽用?Golang AttachToContainerOptions使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了AttachToContainerOptions類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runContainerAttach
// this funtion simply abstracts out the first phase of attaching to the container that was originally in line with the RunContainer() method
func runContainerAttach(attached chan struct{}, container *docker.Container, opts RunContainerOptions, d *stiDocker) *sync.WaitGroup {
attachOpts := docker.AttachToContainerOptions{
Container: container.ID,
Success: attached,
Stream: true,
}
if opts.Stdin != nil {
attachOpts.InputStream = opts.Stdin
attachOpts.Stdin = true
}
if opts.Stdout != nil {
attachOpts.OutputStream = opts.Stdout
attachOpts.Stdout = true
}
if opts.Stderr != nil {
attachOpts.ErrorStream = opts.Stderr
attachOpts.Stderr = true
}
wg := sync.WaitGroup{}
go func() {
wg.Add(1)
defer wg.Done()
if err := d.client.AttachToContainer(attachOpts); err != nil {
glog.Errorf("Unable to attach container with %v", attachOpts)
}
}()
return &wg
}
示例2: runContainerAttachTwo
// this funtion simply abstracts out the second phase of attaching to the container that was originally in line with the RunContainer() method
func runContainerAttachTwo(attached2 chan struct{}, container *docker.Container, opts RunContainerOptions, d *stiDocker, wg sync.WaitGroup) {
attachOpts2 := docker.AttachToContainerOptions{
Container: container.ID,
Success: attached2,
Stream: true,
OutputStream: opts.Stdout,
Stdout: true,
}
if opts.Stderr != nil {
attachOpts2.Stderr = true
attachOpts2.ErrorStream = opts.Stderr
}
go func() {
wg.Add(1)
defer wg.Done()
if err := d.client.AttachToContainer(attachOpts2); err != nil {
glog.Errorf("Unable to attach container with %v", attachOpts2)
}
}()
}
示例3: RunContainer
// RunContainer creates and starts a container using the image specified in the options with the ability
// to stream input or output
func (d *stiDocker) RunContainer(opts RunContainerOptions) (err error) {
// get info about the specified image
image := getImageName(opts.Image)
var imageMetadata *docker.Image
if opts.PullImage {
imageMetadata, err = d.CheckAndPullImage(image)
} else {
imageMetadata, err = d.client.InspectImage(image)
}
if err != nil {
glog.Errorf("Unable to get image metadata for %s: %v", image, err)
return err
}
// base directory for all STI commands
var commandBaseDir string
// untar operation destination directory
tarDestination := opts.Destination
if len(tarDestination) == 0 {
tarDestination = getDestination(imageMetadata)
}
if opts.ExternalScripts {
// for external scripts we must always append 'scripts' because this is
// the default subdirectory inside tar for them
commandBaseDir = filepath.Join(tarDestination, "scripts")
glog.V(2).Infof("Both scripts and untarred source will be placed in '%s'", tarDestination)
} else {
// for internal scripts we can have separate path for scripts and untar operation destination
scriptsURL := opts.ScriptsURL
if len(scriptsURL) == 0 {
scriptsURL = getScriptsURL(imageMetadata)
}
commandBaseDir = strings.TrimPrefix(scriptsURL, "image://")
glog.V(2).Infof("Base directory for STI scripts is '%s'. Untarring destination is '%s'.",
commandBaseDir, tarDestination)
}
cmd := []string{filepath.Join(commandBaseDir, string(opts.Command))}
// when calling assemble script with Stdin parameter set (the tar file)
// we need to first untar the whole archive and only then call the assemble script
if opts.Stdin != nil && (opts.Command == api.Assemble || opts.Command == api.Usage) {
cmd = []string{"/bin/sh", "-c", fmt.Sprintf("tar -C %s -xf - && %s",
tarDestination, filepath.Join(commandBaseDir, string(opts.Command)))}
}
config := docker.Config{
Image: image,
Cmd: cmd,
}
if opts.Env != nil {
config.Env = opts.Env
}
if opts.Stdin != nil {
config.OpenStdin = true
config.StdinOnce = true
}
if opts.Stdout != nil {
config.AttachStdout = true
}
glog.V(2).Infof("Creating container using config: %+v", config)
container, err := d.client.CreateContainer(docker.CreateContainerOptions{Name: "", Config: &config})
if err != nil {
return err
}
defer d.RemoveContainer(container.ID)
glog.V(2).Infof("Attaching to container")
attached := make(chan struct{})
attachOpts := docker.AttachToContainerOptions{
Container: container.ID,
Success: attached,
Stream: true,
}
if opts.Stdin != nil {
attachOpts.InputStream = opts.Stdin
attachOpts.Stdin = true
} else if opts.Stdout != nil {
attachOpts.OutputStream = opts.Stdout
attachOpts.Stdout = true
}
if opts.Stderr != nil {
attachOpts.ErrorStream = opts.Stderr
attachOpts.Stderr = true
}
wg := sync.WaitGroup{}
go func() {
wg.Add(1)
defer wg.Done()
if err := d.client.AttachToContainer(attachOpts); err != nil {
glog.Errorf("Unable to attach container with %v", attachOpts)
}
}()
attached <- <-attached
// If attaching both stdin and stdout or stderr, attach stdout and stderr in
//.........這裏部分代碼省略.........