zoukankan      html  css  js  c++  java
  • docker service create api参数

    =====

    /*
    @Time : 2020/4/25 22:10
    @Author : chenhao
    */
    package controllers
    
    import (
        "github.com/docker/docker/api/types/container"
        "github.com/docker/docker/api/types/mount"
        "github.com/docker/docker/api/types/swarm"
        docker "github.com/fsouza/go-dockerclient"
    
        //docker "github.com/fsouza/go-dockerclient"
    )
    func CreateService() {

    replicas := uint64(3)
    serviceOptions := docker.CreateServiceOptions{
    Auth: docker.AuthConfiguration{},
    ServiceSpec: swarm.ServiceSpec{
    Annotations: swarm.Annotations{
    Name: "test-nginx", // service name
    Labels: nil,
    },
    TaskTemplate: swarm.TaskSpec{ // TaskTemplate定义了在编排此服务时服务应如何构造新任务
    ContainerSpec: &swarm.ContainerSpec{ // 与PluginSpec一起指定时无效。
    Image: "nginx:1.17", // images:tag
    Labels: nil, // 用户定义的键/值数据。
    Command: []string{}, // The command to be run in the image.
    Args: nil, // Arguments to the command
    Hostname: "", // 用于容器的主机名。这必须是有效的RFC 1123主机名
    Env: []string{}, // 环境变量: A list of environment variables in the form VAR=value
    Dir: "", // 运行命令的工作目录: The working directory for commands to run in.( 。)
    User: "", // 用于指定容器内的用户
    Groups: nil, // 容器进程将作为其运行的其他组的列表。: A list of additional groups that the container process will run as.
    Privileges: &swarm.Privileges{
    CredentialSpec: &swarm.CredentialSpec{
    // CredentialSpec.File和CredentialSpec.Registry是互斥的
    Config: "",
    File: "", // 从此文件加载凭据规范。该文件由守护程序读取,并且必须存在于docker数据目录的CredentialSpecs子目录中,该目录在Windows上默认为C:ProgramDataDocker\, 例如,指定spec.json将加载C:ProgramDataDockerCredentialSpecsspec.json
    Registry: "", // 从Windows注册表中的该值加载凭据规范。指定的注册表值必须位于 HKLMSOFTWAREMicrosoftWindows NTCurrentVersionVirtualizationContainersCredentialSpecs
    }, // 托管服务帐户的CredentialSpec(仅Windows)
    SELinuxContext: &swarm.SELinuxContext{
    Disable: false, // 禁用SELinux
    User: "", // SELinux用户标签
    Role: "", // SELinux角色标签
    Type: "", // SELinux类型标签
    Level: "", // SELinux级别标签
    }, // 容器的SELinux标签
    }, // 容器的安全性选项
    Init: nil,
    StopSignal: "", // 停止容器的信号
    TTY: true, // 是否应分配伪TTY
    OpenStdin: false, // Open stdin
    ReadOnly: false, // 将容器的根文件系统挂载为只读。
    Mounts: []mount.Mount{ // 要添加到作为 服务一部分 创建的容器中的 挂载的规范。
    mount.Mount{
    //bind将主机上的文件或目录挂载到容器中。在创建容器之前必须存在。
    //volume用给定的名称和选项创建一个卷(或使用具有相同名称和选项的现有卷)。删除容器时不会删除这些内容。
    //tmpfs使用给定的选项创建一个tmpfs。无法为tmpfs指定安装源。
    Type: "", // 挂载类型 Enum: bind, volume, tmpfs, npipe
    Source: "", // 宿主机路径,挂载源(例如卷名,主机路径)。注意:每个节点机器都要存在这个路径,
    Target: "", // 容器路径
    ReadOnly: false, // 挂载是否为只读。
    Consistency: "", // 挂载的一致性要求:默认,一致,缓存或委托
    BindOptions: &mount.BindOptions{
    Propagation: "", // 绑定类型的可选配置,Enum: private, rprivate, shared, rshared, slave, rslave 值为[r] private,[r] shared或[r] slave的传播模式。
    NonRecursive: false,
    },
    VolumeOptions: &mount.VolumeOptions{
    NoCopy: false, // 用目标数据填充volume
    Labels: nil, // 用户定义的键/值元数据
    DriverConfig: &mount.Driver{
    Name: "", // 用于创建卷的驱动程序的名称
    Options: nil, // 驱动程序特定选项的键/值映射
    }, // 驱动程序特定选项的map
    }, // 卷类型的可选配置
    TmpfsOptions: &mount.TmpfsOptions{
    SizeBytes: 0, // tmpfs的许可模式以整数形式挂载。
    Mode: 0, // tmpfs的大小以字节为单位。
    }, // tmpfs类型的可选配置
    },
    },
    StopGracePeriod: nil, // 在强行杀死容器之前等待容器终止的时间。
    Healthcheck: &container.HealthConfig{ // 进行检查容器是否健康的测试。
    // TEST:要执行的测试。可能的值为:
    // - [] 从image或父image继承健康检查
    // - ["NONE"] 禁用健康检查
    // - ["CMD", args...] 直接执行参数
    // - ["CMD-SHELL", command] 使用系统的默认shell运行命令
    Test: nil,
    Interval: 0, // 两次检查之间等待的时间(以纳秒为单位)。它应该是0或至少1000000(1 ms)。 0表示默认。
    Timeout: 0, // 在考虑将check挂起之前需要等待的时间。它应该是0或至少1000000(1 ms)。 0表示默认
    StartPeriod: 0, // 开始运行状况重试倒计时之前,容器初始化的开始时间(以纳秒为单位)。它应该是0或至少1000000(1 ms)。 0表示默认。
    Retries: 0, // 认为容器不健康所需的连续失败次数。 0表示默认。
    }, // 进行检查容器是否健康的测试
    Hosts: nil, // 要添加到容器的主机文件中的主机名/ IP映射的列表。额外主机的格式在hosts(5)手册页中指定:http://man7.org/linux/man-pages/man5/hosts.5.html
    Configs: nil, // 配置包含对将向服务公开的零个或多个配置的引用: Configs contains references to zero or more configs that will be exposed to the service.
    Isolation: "",
    Sysctls: nil,
    Capabilities: nil,
    DNSConfig: nil,
    Secrets: nil,
    },
    PluginSpec: nil, // 与ContainerSpec一起指定时无效。 (仅实验性发行。)
    NetworkAttachmentSpec: nil,
    Resources: &swarm.ResourceRequirements{
    Limits: &swarm.Resources{
    NanoCPUs: 0,
    MemoryBytes: 0,
    GenericResources: []swarm.GenericResource{
    swarm.GenericResource{
    NamedResourceSpec: &swarm.NamedGenericResource{
    Kind: "",
    Value: "",
    },
    DiscreteResourceSpec: &swarm.DiscreteGenericResource{
    Kind: "",
    Value: 0,
    },
    },
    }, // 用户定义的资源可以是整数资源(例如SSD = 3)或字符串资源(例如GPU = UUID1)
    }, // 一个对象,描述可以由节点发布并由任务请求的资源
    Reservations: nil, // 一个对象,描述可以由节点发布并由任务请求的资源.参考Limits
    }, // 资源要求适用于作为服务的一部分创建的每个单独的容器。
    RestartPolicy: &swarm.RestartPolicy{
    Condition: "", // 重新启动的条件 Enum: none, on-failure, any
    Delay: nil, // 重新启动尝试之间的延迟
    MaxAttempts: nil, // 放弃之前最大尝试重新启动给定容器的次数(默认值为0,将被忽略)
    Window: nil, // Windows是用于评估重新启动策略的时间窗口(默认值为0,它是无界的)
    }, // 重新启动策略的规范,该策略适用于作为此服务的一部分创建的容器。
    Placement: nil,
    Networks: nil,
    LogDriver: &swarm.Driver{
    Name: "",
    Options: nil,
    }, // 指定用于根据此规范创建的任务的日志驱动程序。如果不存在,则将使用swarm群集的默认值,如果未指定,最终将降至engine引擎默认值。
    ForceUpdate: 0, // 即使未更改相关参数也触发更新的计数器
    Runtime: "", // 运行时是为任务执行程序指定的运行时类型
    },
    Mode: swarm.ServiceMode{
    Replicated: &swarm.ReplicatedService{
    Replicas: &replicas, // --replicas 副本数
    },
    },
    UpdateConfig: &swarm.UpdateConfig{
    Parallelism: uint64(2), // --update-parallelism 更新时同时并行更新数量,默认1
    Delay: 10000000000, // 10s --update-delay 每次容器与容器之间的更新时间间隔
    FailureAction: "continue", // --update-failure-action 任务容器更新失败时的模式,(“pause”停止|”continue“继续),默认pause。
    Monitor: nil, // --update-monitor 每次更新任务后的持续时间以监控故障(ns / us / ms / s / m / h)(默认为0)
    MaxFailureRatio: 0, // --update-max-failure-ratio 更新期间容忍的故障率 .数值(列“.2”为%20)
    Order: nil, // --update-order "start-first"|"stop-first" 默认"stop-first"
    },
    RollbackConfig: &swarm.UpdateConfig{
    Parallelism: nil,
    Delay: nil,
    FailureAction: nil,
    Monitor: nil,
    MaxFailureRatio: 0, // --rollback-max-failure-ratio .数值(列“.2”为%20) 回滚故障率如果小于百分比允许运行
    Order: nil,
    },
    Networks: []swarm.NetworkAttachmentConfig{ // --network my-net
    swarm.NetworkAttachmentConfig{
    Target: "", // 网络名称
    Aliases: nil, // 别名
    DriverOpts: nil, // bridge drive 类型
    },
    },
    EndpointSpec: &swarm.EndpointSpec{
    Mode: "",
    Ports: []swarm.PortConfig{ // -p 9180:80
    swarm.PortConfig{
    Name: "",
    Protocol: "tcp", // tcp udp sctp
    TargetPort: 80, // 容器内部端口
    PublishedPort: 9180, // 映射端口
    PublishMode: "", // "ingress":路由网格进行入口负载平衡。 "host":
    },
    },
    },
    },
    Context: nil,
    }

    _, _ = dockerCli.CreateService(serviceOptions)

    }
     
  • 相关阅读:
    java获取包下被指定注解的类
    Only fullscreen activities can request orientation 解决方法
    android 编译时注解
    android AOP编程
    webView渲染富文本
    看美剧神器
    神奇图书馆主题曲 歌词
    工体东路没有人
    微信小程序如何快速开通流量主
    微信小程序入门教程
  • 原文地址:https://www.cnblogs.com/zhzhlong/p/12780417.html
Copyright © 2011-2022 走看看