本文整理匯總了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
}