本文整理汇总了Golang中github.com/docker/engine-api/types/container.HostConfig.Binds方法的典型用法代码示例。如果您正苦于以下问题:Golang HostConfig.Binds方法的具体用法?Golang HostConfig.Binds怎么用?Golang HostConfig.Binds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/engine-api/types/container.HostConfig
的用法示例。
在下文中一共展示了HostConfig.Binds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Process
func (m *UpdateServiceSnapshotByContainer) Process() error {
_, imageName := m.info.GetName()
cached, err := utils.IsImageCached(imageName)
if err != nil {
fmt.Println(err)
return err
}
if !cached {
//TODO: remove this image to save server disk
err := utils.PullImage(imageName)
if err != nil {
return err
}
}
var config container.Config
config.Image = imageName
config.Cmd = []string{snapshotProcess, m.info.CallbackID, m.info.Host, m.info.DataProto}
var hostConfig container.HostConfig
hostConfig.Binds = append(hostConfig.Binds, fmt.Sprintf("%s:%s", m.info.DataURL, snapshotMountDir))
containerName := "scan-" + m.info.CallbackID
err = utils.StartContainer(config, hostConfig, containerName)
return err
}
示例2: TestUtilsContainer
func TestUtilsContainer(t *testing.T) {
//TODO: dockyard dev team should provide small testing containers.
imageName := "google/nodejs"
containerName := ""
cached, err := utils.IsImageCached(imageName)
if err == utils.ErrorsNoDockerClient {
fmt.Println("Please start a docker daemon to continue the container operation test")
return
}
assert.Nil(t, err, "Fail to load Image")
if !cached {
err := utils.PullImage(imageName)
assert.Nil(t, err, "Fail to pull image")
}
tmpFile, err := ioutil.TempFile("/tmp", "dockyard-test-container-oper")
assert.Nil(t, err, "System err, fail to create temp file")
defer os.Remove(tmpFile.Name())
var config container.Config
config.Image = imageName
config.Cmd = []string{"touch", tmpFile.Name()}
var hostConfig container.HostConfig
hostConfig.Binds = append(hostConfig.Binds, "/tmp:/tmp")
utils.StartContainer(config, hostConfig, containerName)
//TODO: stop, remove the container process
assert.Equal(t, true, utils.IsFileExist(tmpFile.Name()), "Fail to touch file by using StartContainer")
}