Skip to content

Commit 1aaa76d

Browse files
authored
Merge pull request #2297 from hannseman/service-init
Add support for setting init on services
2 parents 5e8b1c0 + 0d5aacc commit 1aaa76d

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

docker/api/service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def raise_version_error(param, min_version):
8888
if container_spec.get('Isolation') is not None:
8989
raise_version_error('ContainerSpec.isolation', '1.35')
9090

91+
if utils.version_lt(version, '1.38'):
92+
if container_spec.get('Init') is not None:
93+
raise_version_error('ContainerSpec.init', '1.38')
94+
9195
if task_template.get('Resources'):
9296
if utils.version_lt(version, '1.32'):
9397
if task_template['Resources'].get('GenericResources'):

docker/models/services.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def create(self, image, command=None, **kwargs):
165165
env (list of str): Environment variables, in the form
166166
``KEY=val``.
167167
hostname (string): Hostname to set on the container.
168+
init (boolean): Run an init inside the container that forwards
169+
signals and reaps processes
168170
isolation (string): Isolation technology used by the service's
169171
containers. Only used for Windows containers.
170172
labels (dict): Labels to apply to the service.
@@ -280,6 +282,7 @@ def list(self, **kwargs):
280282
'hostname',
281283
'hosts',
282284
'image',
285+
'init',
283286
'isolation',
284287
'labels',
285288
'mounts',

docker/types/services.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,15 @@ class ContainerSpec(dict):
110110
privileges (Privileges): Security options for the service's containers.
111111
isolation (string): Isolation technology used by the service's
112112
containers. Only used for Windows containers.
113+
init (boolean): Run an init inside the container that forwards signals
114+
and reaps processes.
113115
"""
114116
def __init__(self, image, command=None, args=None, hostname=None, env=None,
115117
workdir=None, user=None, labels=None, mounts=None,
116118
stop_grace_period=None, secrets=None, tty=None, groups=None,
117119
open_stdin=None, read_only=None, stop_signal=None,
118120
healthcheck=None, hosts=None, dns_config=None, configs=None,
119-
privileges=None, isolation=None):
121+
privileges=None, isolation=None, init=None):
120122
self['Image'] = image
121123

122124
if isinstance(command, six.string_types):
@@ -183,6 +185,9 @@ def __init__(self, image, command=None, args=None, hostname=None, env=None,
183185
if isolation is not None:
184186
self['Isolation'] = isolation
185187

188+
if init is not None:
189+
self['Init'] = init
190+
186191

187192
class Mount(dict):
188193
"""

tests/integration/api_service_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,20 @@ def test_create_service_with_privileges(self):
850850
)
851851
assert privileges['SELinuxContext']['Disable'] is True
852852

853+
@requires_api_version('1.38')
854+
def test_create_service_with_init(self):
855+
container_spec = docker.types.ContainerSpec(
856+
'busybox', ['sleep', '999'], init=True
857+
)
858+
task_tmpl = docker.types.TaskTemplate(container_spec)
859+
name = self.get_service_name()
860+
svc_id = self.client.create_service(task_tmpl, name=name)
861+
svc_info = self.client.inspect_service(svc_id)
862+
assert 'Init' in svc_info['Spec']['TaskTemplate']['ContainerSpec']
863+
assert (
864+
svc_info['Spec']['TaskTemplate']['ContainerSpec']['Init'] is True
865+
)
866+
853867
@requires_api_version('1.25')
854868
def test_update_service_with_defaults_name(self):
855869
container_spec = docker.types.ContainerSpec(

0 commit comments

Comments
 (0)