本文整理匯總了Golang中github.com/hyperledger/fabric/core/container/util.NewDockerClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDockerClient函數的具體用法?Golang NewDockerClient怎麽用?Golang NewDockerClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewDockerClient函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Start
//Start starts a container using a previously created docker image
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool) error {
imageID, _ := vm.GetVMName(ccid)
client, err := cutil.NewDockerClient()
if err != nil {
dockerLogger.Debug("start - cannot create client %s", err)
return err
}
containerID := strings.Replace(imageID, ":", "_", -1)
//stop,force remove if necessary
dockerLogger.Debug("Cleanup container %s", containerID)
vm.stopInternal(ctxt, client, containerID, 0, false, false)
dockerLogger.Debug("Start container %s", containerID)
err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout)
if err != nil {
dockerLogger.Error(fmt.Sprintf("start-could not recreate container %s", err))
return err
}
err = client.StartContainer(containerID, &docker.HostConfig{NetworkMode: "host"})
if err != nil {
dockerLogger.Error(fmt.Sprintf("start-could not start container %s", err))
return err
}
dockerLogger.Debug("Started container %s", containerID)
return nil
}
示例2: NewVM
// NewVM creates a new VM instance.
func NewVM() (*VM, error) {
client, err := cutil.NewDockerClient()
if err != nil {
return nil, err
}
VM := &VM{Client: client}
return VM, nil
}
示例3: Deploy
//Deploy use the reader containing targz to create a docker image
//for docker inputbuf is tar reader ready for use by docker.Client
//the stream from end client to peer could directly be this tar stream
//talk to docker daemon using docker Client and build the image
func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
client, err := cutil.NewDockerClient()
switch err {
case nil:
if err = vm.deployImage(client, ccid, args, env, attachstdin, attachstdout, reader); err != nil {
return err
}
default:
return fmt.Errorf("Error creating docker client: %s", err)
}
return nil
}
示例4: Start
//Start starts a container using a previously created docker image
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
imageID, _ := vm.GetVMName(ccid)
client, err := cutil.NewDockerClient()
if err != nil {
dockerLogger.Debugf("start - cannot create client %s", err)
return err
}
containerID := strings.Replace(imageID, ":", "_", -1)
//stop,force remove if necessary
dockerLogger.Debugf("Cleanup container %s", containerID)
vm.stopInternal(ctxt, client, containerID, 0, false, false)
dockerLogger.Debugf("Start container %s", containerID)
err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout)
if err != nil {
//if image not found try to create image and retry
if err == docker.ErrNoSuchImage {
if reader != nil {
dockerLogger.Debugf("start-could not find image ...attempt to recreate image %s", err)
if err = vm.deployImage(client, ccid, args, env, attachstdin, attachstdout, reader); err != nil {
return err
}
dockerLogger.Debug("start-recreated image successfully")
if err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout); err != nil {
dockerLogger.Errorf("start-could not recreate container post recreate image: %s", err)
return err
}
} else {
dockerLogger.Errorf("start-could not find image: %s", err)
return err
}
} else {
dockerLogger.Errorf("start-could not recreate container %s", err)
return err
}
}
// Baohua: getDockerHostConfig() will be ignored when communicating with docker API 1.24+.
// I keep it here for a short-term compatibility.
// See https://goo.gl/ZvtkKm for more details.
err = client.StartContainer(containerID, getDockerHostConfig())
if err != nil {
dockerLogger.Errorf("start-could not start container %s", err)
return err
}
dockerLogger.Debugf("Started container %s", containerID)
return nil
}
示例5: Stop
//Stop stops a running chaincode
func (vm *DockerVM) Stop(ctxt context.Context, ccid ccintf.CCID, timeout uint, dontkill bool, dontremove bool) error {
id, _ := vm.GetVMName(ccid)
client, err := cutil.NewDockerClient()
if err != nil {
dockerLogger.Debugf("start - cannot create client %s", err)
return err
}
id = strings.Replace(id, ":", "_", -1)
err = vm.stopInternal(ctxt, client, id, timeout, dontkill, dontremove)
return err
}
示例6: Start
//Start starts a container using a previously created docker image
func (vm *DockerVM) Start(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
imageID, _ := vm.GetVMName(ccid)
client, err := cutil.NewDockerClient()
if err != nil {
dockerLogger.Debugf("start - cannot create client %s", err)
return err
}
containerID := strings.Replace(imageID, ":", "_", -1)
//stop,force remove if necessary
dockerLogger.Debugf("Cleanup container %s", containerID)
vm.stopInternal(ctxt, client, containerID, 0, false, false)
dockerLogger.Debugf("Start container %s", containerID)
err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout)
if err != nil {
//if image not found try to create image and retry
if err == docker.ErrNoSuchImage {
if reader != nil {
dockerLogger.Debugf("start-could not find image ...attempt to recreate image %s", err)
if err = vm.deployImage(client, ccid, args, env, attachstdin, attachstdout, reader); err != nil {
return err
}
dockerLogger.Debug("start-recreated image successfully")
if err = vm.createContainer(ctxt, client, imageID, containerID, args, env, attachstdin, attachstdout); err != nil {
dockerLogger.Errorf("start-could not recreate container post recreate image: %s", err)
return err
}
} else {
dockerLogger.Errorf("start-could not find image: %s", err)
return err
}
} else {
dockerLogger.Errorf("start-could not recreate container %s", err)
return err
}
}
// start container with HostConfig was deprecated since v1.10 and removed in v1.2
err = client.StartContainer(containerID, nil)
if err != nil {
dockerLogger.Errorf("start-could not start container %s", err)
return err
}
dockerLogger.Debugf("Started container %s", containerID)
return nil
}
示例7: Destroy
//Destroy destroys an image
func (vm *DockerVM) Destroy(ctxt context.Context, ccid ccintf.CCID, force bool, noprune bool) error {
id, _ := vm.GetVMName(ccid)
client, err := cutil.NewDockerClient()
if err != nil {
dockerLogger.Error(fmt.Sprintf("destroy-cannot create client %s", err))
return err
}
id = strings.Replace(id, ":", "_", -1)
err = client.RemoveImageExtended(id, docker.RemoveImageOptions{Force: force, NoPrune: noprune})
if err != nil {
dockerLogger.Error(fmt.Sprintf("error while destroying image: %s", err))
} else {
dockerLogger.Debug("Destroyed image %s", id)
}
return err
}
示例8: Deploy
//Deploy use the reader containing targz to create a docker image
//for docker inputbuf is tar reader ready for use by docker.Client
//the stream from end client to peer could directly be this tar stream
//talk to docker daemon using docker Client and build the image
func (vm *DockerVM) Deploy(ctxt context.Context, ccid ccintf.CCID, args []string, env []string, attachstdin bool, attachstdout bool, reader io.Reader) error {
id, _ := vm.GetVMName(ccid)
outputbuf := bytes.NewBuffer(nil)
opts := docker.BuildImageOptions{
Name: id,
Pull: false,
InputStream: reader,
OutputStream: outputbuf,
}
client, err := cutil.NewDockerClient()
switch err {
case nil:
if err = client.BuildImage(opts); err != nil {
dockerLogger.Error(fmt.Sprintf("Error building Peer container: %s", err))
return err
}
dockerLogger.Debug("Created image: %s", id)
default:
return fmt.Errorf("Error creating docker client: %s", err)
}
return nil
}