coveralls: 
[![Coverage Status](https://coveralls.io/builds/7638771/badge)](https://coveralls.io/builds/7638771)

Coverage remained the same at 100.0% when pulling **b5f87cb77d21bf715abb3a74102224baeffccd53 on esben:container-restart** into **1f7353342a8eda120d4fddb87a14e63f5da799b3 on XD-embedded:master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/7638771/badge)](https://coveralls.io/builds/7638771)

Coverage remained the same at 100.0% when pulling **b5f87cb77d21bf715abb3a74102224baeffccd53 on esben:container-restart** into **1f7353342a8eda120d4fddb87a14e63f5da799b3 on XD-embedded:master**.

diff --git a/xd/docker/client.py b/xd/docker/client.py
index 382c1ec..a0c7398 100644
--- a/xd/docker/client.py
+++ b/xd/docker/client.py
@@ -519,6 +519,10 @@ class DockerClient(object):
         Arguments:
           container: The container to remove (id or name).
           timeout: Number of seconds to wait before killing the container.
+
+        Returns:
+          True if container was stopped.
+          False if container was already stopped.
         """
 
         # Handle convenience argument types
@@ -540,3 +544,31 @@ class DockerClient(object):
                 return False
             raise e
         return True
+
+    def container_restart(self,
+                          container: Union[Container, ContainerName, str],
+                          timeout: Optional[int]=None):
+        """Restart container.
+
+        Restart the container, and optionally killing the container after a
+        timeout waiting for the container to stop.
+
+        Arguments:
+          container: The container to remove (id or name).
+          timeout: Number of seconds to wait before killing the container.
+        """
+
+        # Handle convenience argument types
+        if isinstance(container, str):
+            id_or_name = container
+        elif isinstance(container, ContainerName):
+            id_or_name = container.name
+        else:
+            id_or_name = container.id or container.name
+
+        params = {}
+        if timeout is not None:
+            params['t'] = timeout
+
+        self._post('/containers/{}/restart'.format(id_or_name),
+                   params=params)

client.container_restart()
Client API command to restart a container.
diff --git a/tests/integration/container_restart_test.py b/tests/integration/container_restart_test.py
new file mode 100644
index 0000000..53d998b
--- /dev/null
+++ b/tests/integration/container_restart_test.py
@@ -0,0 +1,26 @@
+import pytest
+import os
+
+from xd.docker.client import *
+
+
+def test_restart(docker, stdout):
+    os.system("docker run -d --name xd-docker-test busybox:latest sleep 5")
+    docker.container_restart('xd-docker-test')
+
+
+def test_already_stopped(docker, stdout):
+    os.system("docker run --name xd-docker-test busybox:latest true")
+    docker.container_restart('xd-docker-test')
+
+
+def test_not_started(docker, stdout):
+    os.system("docker create --name xd-docker-test busybox:latest true")
+    docker.container_restart('xd-docker-test')
+
+
+def test_no_such_container(docker, stdout):
+    with pytest.raises(ClientError) as clienterror:
+        with stdout.redirect():
+            docker.container_stop('xd-docker-test')
+    assert clienterror.value.code == 404
diff --git a/tests/integration/container_stop_test.py b/tests/integration/container_stop_test.py
index e11e8f3..3aaa43b 100644
--- a/tests/integration/container_stop_test.py
+++ b/tests/integration/container_stop_test.py
@@ -1,6 +1,5 @@
 import pytest
 import os
-import time
 
 from xd.docker.client import *
 
diff --git a/tests/unit/client_test.py b/tests/unit/client_test.py
index 6bf24f2..e890e2d 100644
--- a/tests/unit/client_test.py
+++ b/tests/unit/client_test.py
@@ -1320,3 +1320,37 @@ class container_stop_tests(ContextClientTestCase):
         params = post_mock.call_args[1]['params']
         assert 't' in params
         assert params['t'] == 42
+
+
+class container_restart_tests(ContextClientTestCase):
+
+    @mock.patch('requests.post')
+    def test_normal(self, post_mock):
+        post_mock.return_value = requests_mock.Response(None, 204)
+        self.client.container_restart("foobar")
+
+    @mock.patch('requests.post')
+    def test_no_such_container(self, post_mock):
+        post_mock.return_value = requests_mock.Response(None, 404)
+        with pytest.raises(ClientError) as clienterror:
+            self.client.container_restart('foobar')
+        assert clienterror.value.code == 404
+
+    @mock.patch('requests.post')
+    def test_containername(self, post_mock):
+        post_mock.return_value = requests_mock.Response(None, 204)
+        self.client.container_restart(ContainerName("foobar"))
+
+    @mock.patch('requests.post')
+    def test_container(self, post_mock):
+        post_mock.return_value = requests_mock.Response(None, 204)
+        self.client.container_restart(Container(self.client,name="foobar"))
+
+    @mock.patch('requests.post')
+    def test_timeout(self, post_mock):
+        post_mock.return_value = requests_mock.Response(None, 204)
+        self.client.container_restart("foobar", timeout=42)
+        assert 'params' in post_mock.call_args[1]
+        params = post_mock.call_args[1]['params']
+        assert 't' in params
+        assert params['t'] == 42

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov mock flake8
3.9
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
certifi==2025.1.31
charset-normalizer==3.4.1
coverage==7.8.0
exceptiongroup==1.2.2
flake8==7.2.0
idna==3.10
iniconfig==2.1.0
mccabe==0.7.0
mock==5.2.0
packaging==24.2
pluggy==1.5.0
pycodestyle==2.13.0
pyflakes==3.3.2
pytest==8.3.5
pytest-cov==6.0.0
requests==2.32.3
requests-unixsocket==0.4.1
tomli==2.2.1
typing==3.7.4.3
urllib3==2.3.0
-e git+https://github.com/XD-embedded/xd-docker.git@1f7353342a8eda120d4fddb87a14e63f5da799b3#egg=XD_Docker

name: xd-docker
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - certifi==2025.1.31
      - charset-normalizer==3.4.1
      - coverage==7.8.0
      - exceptiongroup==1.2.2
      - flake8==7.2.0
      - idna==3.10
      - iniconfig==2.1.0
      - mccabe==0.7.0
      - mock==5.2.0
      - packaging==24.2
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.2
      - pytest==8.3.5
      - pytest-cov==6.0.0
      - requests==2.32.3
      - requests-unixsocket==0.4.1
      - tomli==2.2.1
      - typing==3.7.4.3
      - urllib3==2.3.0
prefix: /opt/conda/envs/xd-docker

tests/unit/client_test.py::container_restart_tests::test_container tests/unit/client_test.py::container_restart_tests::test_containername tests/unit/client_test.py::container_restart_tests::test_no_such_container tests/unit/client_test.py::container_restart_tests::test_normal tests/unit/client_test.py::container_restart_tests::test_timeout
tests/integration/container_restart_test.py::test_restart tests/integration/container_restart_test.py::test_already_stopped tests/integration/container_restart_test.py::test_not_started tests/integration/container_restart_test.py::test_no_such_container tests/integration/container_stop_test.py::test_stop tests/integration/container_stop_test.py::test_already_stopped tests/integration/container_stop_test.py::test_not_started tests/integration/container_stop_test.py::test_no_such_container
tests/unit/client_test.py::init_tests::test_init_foobar tests/unit/client_test.py::init_tests::test_init_http tests/unit/client_test.py::init_tests::test_init_http_unix tests/unit/client_test.py::init_tests::test_init_noargs tests/unit/client_test.py::init_tests::test_init_tcp tests/unit/client_test.py::init_tests::test_init_unix tests/unit/client_test.py::version_tests::test_version tests/unit/client_test.py::version_tests::test_version_httperror_404 tests/unit/client_test.py::version_tests::test_version_httperror_500 tests/unit/client_test.py::version_tests::test_version_httperror_unknown tests/unit/client_test.py::ping_tests::test_ping tests/unit/client_test.py::ping_tests::test_ping_server_error tests/unit/client_test.py::containers_tests::test_containers_1 tests/unit/client_test.py::containers_tests::test_containers_3 tests/unit/client_test.py::containers_tests::test_containers_4 tests/unit/client_test.py::containers_tests::test_containers_only_running_false tests/unit/client_test.py::images_tests::test_images tests/unit/client_test.py::image_inspect_tests::test_image_inspect tests/unit/client_test.py::image_inspect_tests::test_image_inspect_raw tests/unit/client_test.py::image_build_tests::test_image_build tests/unit/client_test.py::image_build_tests::test_image_build_context_as_file tests/unit/client_test.py::image_build_tests::test_image_build_context_does_not_exist tests/unit/client_test.py::image_build_tests::test_image_build_invalid_pull tests/unit/client_test.py::image_build_tests::test_image_build_invalid_rm tests/unit/client_test.py::image_build_tests::test_image_build_invalid_tag_1 tests/unit/client_test.py::image_build_tests::test_image_build_invalid_tag_2 tests/unit/client_test.py::image_build_tests::test_image_build_nonstandard_dockerfile tests/unit/client_test.py::image_build_tests::test_image_build_run_error tests/unit/client_test.py::image_build_tests::test_image_build_server_error tests/unit/client_test.py::image_build_tests::test_image_build_with_args tests/unit/client_test.py::image_build_tests::test_image_build_with_forcerm tests/unit/client_test.py::image_build_tests::test_image_build_with_name tests/unit/client_test.py::image_build_tests::test_image_build_with_nocache tests/unit/client_test.py::image_build_tests::test_image_build_with_norm tests/unit/client_test.py::image_build_tests::test_image_build_with_only_error_output tests/unit/client_test.py::image_build_tests::test_image_build_with_pull tests/unit/client_test.py::image_build_tests::test_image_build_with_registry_config tests/unit/client_test.py::image_pull_tests::test_image_pull_1_ok tests/unit/client_test.py::image_pull_tests::test_image_pull_2_not_found tests/unit/client_test.py::image_pull_tests::test_image_pull_3_authconfig tests/unit/client_test.py::image_pull_tests::test_image_pull_4_invalid_authconfig tests/unit/client_test.py::image_remove_tests::test_image_remove_1 tests/unit/client_test.py::image_remove_tests::test_image_remove_2_not_found tests/unit/client_test.py::image_tag_tests::test_image_tag_1_repo tests/unit/client_test.py::image_tag_tests::test_image_tag_2_repo_and_tag tests/unit/client_test.py::image_tag_tests::test_image_tag_3_force tests/unit/client_test.py::image_tag_tests::test_image_tag_4_fail tests/unit/client_test.py::container_create_tests::test_container_create_1_anon tests/unit/client_test.py::container_create_tests::test_container_create_2_named tests/unit/client_test.py::container_create_tests::test_container_create_3_named_str tests/unit/client_test.py::container_create_tests::test_container_create_nopull_needed tests/unit/client_test.py::container_create_tests::test_container_create_nopull_not_needed tests/unit/client_test.py::container_create_tests::test_container_create_pull_needed tests/unit/client_test.py::container_create_tests::test_container_create_pull_not_needed tests/unit/client_test.py::container_create_tests::test_container_create_with_command tests/unit/client_test.py::container_create_tests::test_container_create_with_env tests/unit/client_test.py::container_create_tests::test_container_create_with_exposed_ports tests/unit/client_test.py::container_create_tests::test_container_create_with_memory tests/unit/client_test.py::container_create_tests::test_container_create_with_memory_and_swap tests/unit/client_test.py::container_create_tests::test_container_create_with_network_false tests/unit/client_test.py::container_create_tests::test_container_create_with_oom_kill_false tests/unit/client_test.py::container_create_tests::test_container_create_with_swap_but_not_memory tests/unit/client_test.py::container_remove_tests::test_container_with_id tests/unit/client_test.py::container_remove_tests::test_container_with_id_and_name tests/unit/client_test.py::container_remove_tests::test_container_with_name tests/unit/client_test.py::container_remove_tests::test_containername tests/unit/client_test.py::container_remove_tests::test_force_false tests/unit/client_test.py::container_remove_tests::test_force_true tests/unit/client_test.py::container_remove_tests::test_no_such_container tests/unit/client_test.py::container_remove_tests::test_ok tests/unit/client_test.py::container_remove_tests::test_volumes_false tests/unit/client_test.py::container_remove_tests::test_volumes_true tests/unit/client_test.py::container_start_tests::test_already_running tests/unit/client_test.py::container_start_tests::test_container_with_id tests/unit/client_test.py::container_start_tests::test_container_with_id_and_name tests/unit/client_test.py::container_start_tests::test_container_with_name tests/unit/client_test.py::container_start_tests::test_containername tests/unit/client_test.py::container_start_tests::test_no_such_container tests/unit/client_test.py::container_start_tests::test_str tests/unit/client_test.py::container_wait_tests::test_0 tests/unit/client_test.py::container_wait_tests::test_42 tests/unit/client_test.py::container_wait_tests::test_container tests/unit/client_test.py::container_wait_tests::test_containername tests/unit/client_test.py::container_wait_tests::test_no_such_container tests/unit/client_test.py::container_stop_tests::test_already_stopped tests/unit/client_test.py::container_stop_tests::test_container tests/unit/client_test.py::container_stop_tests::test_containername tests/unit/client_test.py::container_stop_tests::test_no_such_container tests/unit/client_test.py::container_stop_tests::test_normal tests/unit/client_test.py::container_stop_tests::test_timeout
xd/docker/client.py
xd/docker/client.py