本文整理汇总了Golang中github.com/docker/engine-api/types/container.HostConfig.Tmpfs方法的典型用法代码示例。如果您正苦于以下问题:Golang HostConfig.Tmpfs方法的具体用法?Golang HostConfig.Tmpfs怎么用?Golang HostConfig.Tmpfs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/engine-api/types/container.HostConfig
的用法示例。
在下文中一共展示了HostConfig.Tmpfs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newContainer
func newContainer(ctx context.Context, client *client.Client, profile *Profile, name, executable string, args, env map[string]string) (pr *process, err error) {
defer apexctx.GetLogger(ctx).Trace("spawning container").Stop(&err)
var image string
if registry := profile.Registry; registry != "" {
image = registry + "/" + name
} else {
image = name
}
var Env = make([]string, 0, len(env))
for k, v := range env {
Env = append(Env, k+"="+v)
}
var binds = make([]string, 1, len(profile.Binds)+1)
binds[0] = filepath.Dir(args["--endpoint"]) + ":" + profile.RuntimePath
binds = append(binds, profile.Binds...)
// update args["--endpoint"] according to the container's point of view
args["--endpoint"] = filepath.Join(profile.RuntimePath, filepath.Base(args["--endpoint"]))
var Cmd = make(strslice.StrSlice, 1, len(args)+1)
Cmd[0] = executable
for k, v := range args {
Cmd = append(Cmd, k, v)
}
config := container.Config{
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Env: Env,
Cmd: Cmd,
Image: image,
WorkingDir: profile.Cwd,
Labels: map[string]string{isolateDockerLabel: name},
}
apexctx.GetLogger(ctx).Info("applying Resource limits")
var resources = container.Resources{
Memory: profile.Resources.Memory,
CPUShares: profile.Resources.CPUShares,
CPUPeriod: profile.Resources.CPUPeriod,
CPUQuota: profile.Resources.CPUQuota,
CpusetCpus: profile.Resources.CpusetCpus,
CpusetMems: profile.Resources.CpusetMems,
}
hostConfig := container.HostConfig{
NetworkMode: profile.NetworkMode,
Binds: binds,
Resources: resources,
}
if len(profile.Tmpfs) != 0 {
buff := new(bytes.Buffer)
for k, v := range profile.Tmpfs {
fmt.Fprintf(buff, "%s: %s;", k, v)
}
apexctx.GetLogger(ctx).Infof("mounting `tmpfs` to container: %s", buff.String())
hostConfig.Tmpfs = profile.Tmpfs
}
// NOTE: It should be nil
var networkingConfig *network.NetworkingConfig
resp, err := client.ContainerCreate(ctx, &config, &hostConfig, networkingConfig, "")
if err != nil {
apexctx.GetLogger(ctx).WithError(err).Error("unable to create a container")
return nil, err
}
for _, warn := range resp.Warnings {
apexctx.GetLogger(ctx).Warnf("%s warning: %s", resp.ID, warn)
}
ctx, cancel := context.WithCancel(ctx)
pr = &process{
ctx: ctx,
cancellation: cancel,
client: client,
containerID: resp.ID,
}
return pr, nil
}