本文整理匯總了Golang中github.com/docker/engine-api/types/container.HostConfig.VolumesFrom方法的典型用法代碼示例。如果您正苦於以下問題:Golang HostConfig.VolumesFrom方法的具體用法?Golang HostConfig.VolumesFrom怎麽用?Golang HostConfig.VolumesFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/docker/engine-api/types/container.HostConfig
的用法示例。
在下文中一共展示了HostConfig.VolumesFrom方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: OneShot
// OneShot runs a container, expecting it to successfully run to completion
// and die, after which it is removed. Not goroutine safe: only one OneShot
// can be running at once.
// Adds the same binds as the cluster containers (certs, binary, etc).
func (l *LocalCluster) OneShot(
ref string,
ipo types.ImagePullOptions,
containerConfig container.Config,
hostConfig container.HostConfig,
name string,
) error {
if err := pullImage(l, ref, ipo); err != nil {
return err
}
hostConfig.VolumesFrom = []string{l.vols.id}
container, err := createContainer(l, containerConfig, hostConfig, name)
if err != nil {
return err
}
l.oneshot = container
defer func() {
if err := l.oneshot.Remove(); err != nil {
log.Errorf("ContainerRemove: %s", err)
}
l.oneshot = nil
}()
if err := l.oneshot.Start(); err != nil {
return err
}
return l.oneshot.Wait()
}
示例2: createRoach
func (l *LocalCluster) createRoach(node *testNode, vols *Container, cmd ...string) {
l.panicOnStop()
hostConfig := container.HostConfig{
PublishAllPorts: true,
NetworkMode: container.NetworkMode(l.networkID),
}
if vols != nil {
hostConfig.VolumesFrom = append(hostConfig.VolumesFrom, vols.id)
}
var hostname string
if node.index >= 0 {
hostname = fmt.Sprintf("roach%d", node.index)
}
var entrypoint []string
if *cockroachImage == builderImageFull {
entrypoint = append(entrypoint, "/"+filepath.Base(*cockroachBinary))
} else if *cockroachEntry != "" {
entrypoint = append(entrypoint, *cockroachEntry)
}
var err error
node.Container, err = createContainer(
l,
container.Config{
Hostname: hostname,
Image: *cockroachImage,
ExposedPorts: map[nat.Port]struct{}{
defaultTCP: {},
},
Entrypoint: entrypoint,
// TODO(pmattis): Figure out why the Go DNS resolver is misbehaving.
Env: []string{"GODEBUG=netdns=cgo"},
Cmd: cmd,
Labels: map[string]string{
// Allow for `docker ps --filter label=Hostname=roach0` or `--filter label=Roach`.
"Hostname": hostname,
"Roach": "",
},
},
hostConfig,
&network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
l.networkID: {
Aliases: []string{hostname},
},
},
},
node.nodeStr,
)
maybePanic(err)
}
示例3: createRoach
func (l *LocalCluster) createRoach(i int, dns, vols *Container, cmd ...string) *Container {
l.panicOnStop()
hostConfig := container.HostConfig{
PublishAllPorts: true,
}
if dns != nil {
ci, err := dns.Inspect()
maybePanic(err)
hostConfig.DNS = append(hostConfig.DNS, ci.NetworkSettings.IPAddress)
}
if vols != nil {
hostConfig.VolumesFrom = append(hostConfig.VolumesFrom, vols.id)
}
var hostname string
if i >= 0 {
hostname = fmt.Sprintf("roach%d", i)
}
var entrypoint []string
if *cockroachImage == builderImage {
entrypoint = append(entrypoint, "/"+filepath.Base(*cockroachBinary))
} else if *cockroachEntry != "" {
entrypoint = append(entrypoint, *cockroachEntry)
}
c, err := createContainer(
l,
container.Config{
Hostname: hostname,
Domainname: domain,
Image: *cockroachImage,
ExposedPorts: map[nat.Port]struct{}{
cockroachTCP: {},
pgTCP: {},
},
Entrypoint: strslice.New(entrypoint...),
Cmd: strslice.New(cmd...),
Labels: map[string]string{
// Allow for `docker ps --filter label=Hostname=roach0` or `--filter label=Roach`.
"Hostname": hostname,
"Roach": "",
},
},
hostConfig,
nodeStr(i),
)
maybePanic(err)
return c
}
示例4: createRoach
func (l *LocalCluster) createRoach(node *testNode, vols *Container, env []string, cmd ...string) {
l.panicOnStop()
hostConfig := container.HostConfig{
PublishAllPorts: true,
NetworkMode: container.NetworkMode(l.networkID),
Privileged: l.privileged,
}
if vols != nil {
hostConfig.VolumesFrom = append(hostConfig.VolumesFrom, vols.id)
}
var hostname string
if node.index >= 0 {
hostname = fmt.Sprintf("roach%d", node.index)
}
var entrypoint []string
if *cockroachImage == builderImageFull {
entrypoint = append(entrypoint, "/"+filepath.Base(*cockroachBinary))
} else if *cockroachEntry != "" {
entrypoint = append(entrypoint, *cockroachEntry)
}
var err error
node.Container, err = createContainer(
l,
container.Config{
Hostname: hostname,
Image: *cockroachImage,
ExposedPorts: map[nat.Port]struct{}{
DefaultTCP: {},
defaultHTTP: {},
},
Entrypoint: entrypoint,
Env: env,
Cmd: cmd,
Labels: map[string]string{
// Allow for `docker ps --filter label=Hostname=roach0` or `--filter label=Roach`.
"Hostname": hostname,
"Roach": "",
},
},
hostConfig,
node.nodeStr,
)
maybePanic(err)
}