本文整理汇总了Golang中github.com/samalba/dockerclient.ContainerConfig类的典型用法代码示例。如果您正苦于以下问题:Golang ContainerConfig类的具体用法?Golang ContainerConfig怎么用?Golang ContainerConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerConfig类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: consolidateResourceFields
// FIXME: Temporary fix to handle forward/backward compatibility between Docker <1.6 and >=1.7
// ContainerConfig should be handling converting to/from different docker versions
func consolidateResourceFields(c *dockerclient.ContainerConfig) {
if c.Memory != c.HostConfig.Memory {
if c.Memory != 0 {
c.HostConfig.Memory = c.Memory
} else {
c.Memory = c.HostConfig.Memory
}
}
if c.MemorySwap != c.HostConfig.MemorySwap {
if c.MemorySwap != 0 {
c.HostConfig.MemorySwap = c.MemorySwap
} else {
c.MemorySwap = c.HostConfig.MemorySwap
}
}
if c.CpuShares != c.HostConfig.CpuShares {
if c.CpuShares != 0 {
c.HostConfig.CpuShares = c.CpuShares
} else {
c.CpuShares = c.HostConfig.CpuShares
}
}
if c.Cpuset != c.HostConfig.CpusetCpus {
if c.Cpuset != "" {
c.HostConfig.CpusetCpus = c.Cpuset
} else {
c.Cpuset = c.HostConfig.CpusetCpus
}
}
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:35,代码来源:config.go
示例2: Encode
// Encode encodes the build script as a command in the
// provided Container config. For linux, the build script
// is embedded as the container entrypoint command, base64
// encoded as a one-line script.
func Encode(w *plugin.Workspace, c *dockerclient.ContainerConfig, n *parser.DockerNode) {
var buf bytes.Buffer
buf.WriteString(setupScript)
buf.WriteString(forceYesScript)
if w != nil && w.Keys != nil && w.Netrc != nil {
buf.WriteString(writeKey(
w.Keys.Private,
))
buf.WriteString(writeNetrc(
w.Netrc.Machine,
w.Netrc.Login,
w.Netrc.Password,
))
}
if len(n.Shell) > 0 {
buf.WriteString(fmt.Sprintf("%s << \"EOF\"", n.Shell))
}
buf.WriteString(writeCmds(n.Commands))
if len(n.Shell) > 0 {
buf.WriteString("EOF")
}
buf.WriteString(teardownScript)
c.Entrypoint = entrypoint
c.Cmd = []string{encode(buf.Bytes())}
}
开发者ID:fracting,项目名称:drone-exec,代码行数:35,代码来源:script.go
示例3: maybeEscalate
func maybeEscalate(conf dockerclient.ContainerConfig, node *parser.DockerNode) {
if node.Image == "plugins/drone-docker" || node.Image == "plugins/drone-gcr" || node.Image == "plugins/drone-ecr" {
return
}
conf.Volumes = nil
conf.HostConfig.NetworkMode = ""
conf.HostConfig.Privileged = true
conf.Entrypoint = []string{}
conf.Cmd = []string{}
}
开发者ID:fracting,项目名称:drone-exec,代码行数:10,代码来源:build.go
示例4: BuildContainerConfig
// BuildContainerConfig creates a cluster.ContainerConfig from a dockerclient.ContainerConfig
func BuildContainerConfig(c dockerclient.ContainerConfig) *ContainerConfig {
var (
affinities []string
constraints []string
env []string
)
// only for tests
if c.Labels == nil {
c.Labels = make(map[string]string)
}
// parse affinities from labels (ex. docker run --label 'com.docker.swarm.affinities=["container==redis","image==nginx"]')
if labels, ok := c.Labels[SwarmLabelNamespace+".affinities"]; ok {
json.Unmarshal([]byte(labels), &affinities)
}
// parse constraints from labels (ex. docker run --label 'com.docker.swarm.constraints=["region==us-east","storage==ssd"]')
if labels, ok := c.Labels[SwarmLabelNamespace+".constraints"]; ok {
json.Unmarshal([]byte(labels), &constraints)
}
// parse affinities/constraints from env (ex. docker run -e affinity:container==redis -e affinity:image==nginx -e constraint:region==us-east -e constraint:storage==ssd)
for _, e := range c.Env {
if ok, key, value := parseEnv(e); ok && key == "affinity" {
affinities = append(affinities, value)
} else if ok && key == "constraint" {
constraints = append(constraints, value)
} else {
env = append(env, e)
}
}
// remove affinities/constraints from env
c.Env = env
// store affinities in labels
if len(affinities) > 0 {
if labels, err := json.Marshal(affinities); err == nil {
c.Labels[SwarmLabelNamespace+".affinities"] = string(labels)
}
}
// store constraints in labels
if len(constraints) > 0 {
if labels, err := json.Marshal(constraints); err == nil {
c.Labels[SwarmLabelNamespace+".constraints"] = string(labels)
}
}
consolidateResourceFields(&c)
return &ContainerConfig{c}
}
开发者ID:waterytowers,项目名称:global-hack-day-3,代码行数:55,代码来源:config.go
示例5: CreateContainer
// CreateContainer creates a container and internally
// caches its container id.
func (c *Client) CreateContainer(conf *dockerclient.ContainerConfig, name string, auth *dockerclient.AuthConfig) (string, error) {
conf.Env = append(conf.Env, "affinity:container=="+c.info.Id)
id, err := c.Client.CreateContainer(conf, name, auth)
if err == nil {
c.names = append(c.names, id)
}
return id, err
}
开发者ID:objectpartners,项目名称:drone-exec,代码行数:10,代码来源:docker.go
示例6: startDevice
func startDevice(devType string, sn string, server string, docker *dc.DockerClient) error {
// try to start the associated docker container
var cfg dc.ContainerConfig
cfg.Image = "device-" + devType
cfg.Env = []string{"DEVICE_SN=" + sn, "DEVICE_SERVER=" + server}
cfg.Tty = true
cfg.AttachStdout = true
cfg.AttachStdin = false
cfg.AttachStderr = true
id, err := docker.CreateContainer(&cfg, "device"+sn)
if err != nil {
return err
}
var host dc.HostConfig
err = docker.StartContainer(id, &host)
return err
}
开发者ID:jvermillard,项目名称:daas,代码行数:24,代码来源:main.go
示例7: CreateService
func CreateService(config *ServiceConfig) ([]string, error) {
swarm, err := swarmclient.NewSwarmClient()
if err != nil {
log.Fatalf("service.CreateService():%s\n", err)
return nil, err
}
containerIds := make([]string, 0)
containerConfig := new(dockerclient.ContainerConfig)
containerConfig.Image = config.Spec.Image
containerConfig.Labels = config.Metadata.Labels
portBindings := make(map[string][]dockerclient.PortBinding)
containerConfig.Env = config.Spec.Selector
containerConfig.Cmd = config.Spec.Cmd
//exposed ports , so that others can't use
if len(config.Spec.Ports) > 0 {
ports := make(map[string]struct{})
for index := range config.Spec.Ports {
port := strconv.Itoa(config.Spec.Ports[index])
ports[port] = struct{}{}
}
containerConfig.ExposedPorts = ports
}
// intit hostconfig. use host, create and start containers
hostConfig := &dockerclient.HostConfig{}
if config.Spec.Resources.NetworkMode != "" {
hostConfig.NetworkMode = config.Spec.Resources.NetworkMode
} else {
hostConfig.NetworkMode = "host"
}
// use to filter Resources
hostConfig.CpuShares = config.Spec.Resources.CpuShares
hostConfig.CpusetCpus = config.Spec.Resources.CpusetCpus
hostConfig.Memory = config.Spec.Resources.Memory
hostConfig.MemorySwap = config.Spec.Resources.MemorySwap
cpuQuota, err := strconv.Atoi(config.Spec.Resources.CpuQuota)
if err != nil {
hostConfig.CpuQuota = 0
} else {
hostConfig.CpuQuota = int64(cpuQuota)
}
// replicas
numOfTimes := 0
if config.Spec.Replicas > 0 {
numOfTimes = config.Spec.Replicas
} else if config.Spec.Replicas == 0 {
numOfTimes = len(config.Spec.Ips)
//****
if len(config.Spec.Ports) == 0 {
err := fmt.Errorf("service.CreateService():%+s Give ips but not give ports\n", config.Metadata.Name)
log.Error(err)
return nil, err
}
}
for i := 0; i < numOfTimes; i++ {
// use to filter specific ips and ports
for _, port := range config.Spec.Ports {
portbinding := &dockerclient.PortBinding{HostPort: strconv.Itoa(port)}
if len(config.Spec.Ips) > 0 {
portbinding.HostIp = config.Spec.Ips[i]
}
portBindings[strconv.Itoa(port)] = []dockerclient.PortBinding{*portbinding}
}
hostConfig.PortBindings = portBindings
// hostconfig
containerConfig.HostConfig = *hostConfig
// give container different name
containerName := config.Metadata.Name
if role := config.Metadata.Labels["role"]; role != "" {
containerName += "_" + role
}
containerName += strconv.Itoa(i)
log.Debugf("service.CreateService():containerName:%s ; containerConfig:%+v\n", containerName, containerConfig)
//create container
containerId, err := swarm.CreateContainer(containerConfig, containerName)
log.Debugf("service.CreateService():containerId:%s\n", containerId)
if err != nil {
log.Fatalf("service.CreateService():%s\n", err)
fmt.Printf("[error]service.CreateService():%+v\n", err)
}
containerIds = append(containerIds, containerId)
if config.Metadata.Labels["type"] != "libvirt" {
//docker start container,libvirt do not need to start
swarm.StartContainer(containerId, hostConfig)
if err != nil {
log.Fatalf("service.CreateService():%s\n", err)
fmt.Printf("[error]service.CreateService():%+v\n", err)
return nil, err
}
}
}
//.........这里部分代码省略.........
开发者ID:yansmallb,项目名称:tycoon-go,代码行数:101,代码来源:service.go
注:本文中的github.com/samalba/dockerclient.ContainerConfig类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论