@@ -1074,7 +1074,7 @@ def resize(self, container, height, width):
1074
1074
self ._raise_for_status (res )
1075
1075
1076
1076
@utils .check_resource ('container' )
1077
- def restart (self , container , timeout = 10 ):
1077
+ def restart (self , container , timeout = 10 , signal = None ):
1078
1078
"""
1079
1079
Restart a container. Similar to the ``docker restart`` command.
1080
1080
@@ -1084,6 +1084,7 @@ def restart(self, container, timeout=10):
1084
1084
timeout (int): Number of seconds to try to stop for before killing
1085
1085
the container. Once killed it will then be restarted. Default
1086
1086
is 10 seconds.
1087
+ signal (str or int): The signal to send. Defaults to ``SIGTERM``
1087
1088
1088
1089
Raises:
1089
1090
:py:class:`docker.errors.APIError`
@@ -1092,6 +1093,10 @@ def restart(self, container, timeout=10):
1092
1093
params = {'t' : timeout }
1093
1094
url = self ._url ("/containers/{0}/restart" , container )
1094
1095
conn_timeout = self .timeout
1096
+ if signal is not None :
1097
+ if not isinstance (signal , str ):
1098
+ signal = int (signal )
1099
+ params ["signal" ] = signal
1095
1100
if conn_timeout is not None :
1096
1101
conn_timeout += timeout
1097
1102
res = self ._post (url , params = params , timeout = conn_timeout )
@@ -1184,7 +1189,7 @@ def stats(self, container, decode=None, stream=True, one_shot=None):
1184
1189
return self ._result (self ._get (url , params = params ), json = True )
1185
1190
1186
1191
@utils .check_resource ('container' )
1187
- def stop (self , container , timeout = None ):
1192
+ def stop (self , container , timeout = None , signal = None ):
1188
1193
"""
1189
1194
Stops a container. Similar to the ``docker stop`` command.
1190
1195
@@ -1194,6 +1199,7 @@ def stop(self, container, timeout=None):
1194
1199
stop before sending a ``SIGKILL``. If None, then the
1195
1200
StopTimeout value of the container will be used.
1196
1201
Default: None
1202
+ signal (str or int): The signal to send. Defaults to ``SIGTERM``
1197
1203
1198
1204
Raises:
1199
1205
:py:class:`docker.errors.APIError`
@@ -1206,6 +1212,10 @@ def stop(self, container, timeout=None):
1206
1212
params = {'t' : timeout }
1207
1213
url = self ._url ("/containers/{0}/stop" , container )
1208
1214
conn_timeout = self .timeout
1215
+ if signal is not None :
1216
+ if not isinstance (signal , str ):
1217
+ signal = int (signal )
1218
+ params ["signal" ] = signal
1209
1219
if conn_timeout is not None :
1210
1220
conn_timeout += timeout
1211
1221
res = self ._post (url , params = params , timeout = conn_timeout )
0 commit comments