MCPcopy Index your code
hub / github.com/docker/docker-py / create_service

Method create_service

docker/api/service.py:116–189  ·  view source on GitHub ↗

Create a service. Args: task_template (TaskTemplate): Specification of the task to start as part of the new service. name (string): User-defined name for the service. Optional. labels (dict): A map of labels to associate with the

(
            self, task_template, name=None, labels=None, mode=None,
            update_config=None, networks=None, endpoint_config=None,
            endpoint_spec=None, rollback_config=None
    )

Source from the content-addressed store, hash-verified

114class ServiceApiMixin:
115 @utils.minimum_version('1.24')
116 def create_service(
117 self, task_template, name=None, labels=None, mode=None,
118 update_config=None, networks=None, endpoint_config=None,
119 endpoint_spec=None, rollback_config=None
120 ):
121 """
122 Create a service.
123
124 Args:
125 task_template (TaskTemplate): Specification of the task to start as
126 part of the new service.
127 name (string): User-defined name for the service. Optional.
128 labels (dict): A map of labels to associate with the service.
129 Optional.
130 mode (ServiceMode): Scheduling mode for the service (replicated
131 or global). Defaults to replicated.
132 update_config (UpdateConfig): Specification for the update strategy
133 of the service. Default: ``None``
134 rollback_config (RollbackConfig): Specification for the rollback
135 strategy of the service. Default: ``None``
136 networks (:py:class:`list`): List of network names or IDs or
137 :py:class:`~docker.types.NetworkAttachmentConfig` to attach the
138 service to. Default: ``None``.
139 endpoint_spec (EndpointSpec): Properties that can be configured to
140 access and load balance a service. Default: ``None``.
141
142 Returns:
143 A dictionary containing an ``ID`` key for the newly created
144 service.
145
146 Raises:
147 :py:class:`docker.errors.APIError`
148 If the server returns an error.
149 """
150
151 _check_api_features(
152 self._version, task_template, update_config, endpoint_spec,
153 rollback_config
154 )
155
156 url = self._url('/services/create')
157 headers = {}
158 image = task_template.get('ContainerSpec', {}).get('Image', None)
159 if image is None:
160 raise errors.DockerException(
161 'Missing mandatory Image key in ContainerSpec'
162 )
163 if mode and not isinstance(mode, dict):
164 mode = ServiceMode(mode)
165
166 registry, repo_name = auth.resolve_repository_name(image)
167 auth_header = auth.get_config_header(self, registry)
168 if auth_header:
169 headers['X-Registry-Auth'] = auth_header
170 if utils.version_lt(self._version, '1.25'):
171 networks = networks or task_template.pop('Networks', None)
172 data = {
173 'Name': name,

Calls 6

_check_api_featuresFunction · 0.85
ServiceModeClass · 0.85
_urlMethod · 0.80
_resultMethod · 0.80
_post_jsonMethod · 0.80
getMethod · 0.45