@@ -353,14 +353,26 @@ def test_exec_run_success(self):
353353 assert exec_output [0 ] == 0
354354 assert exec_output [1 ] == b"hello\n "
355355
356+ def test_exec_run_error_code_from_exec (self ):
357+ client = docker .from_env (version = TEST_API_VERSION )
358+ container = client .containers .run (
359+ "alpine" , "sh -c 'sleep 20'" , detach = True
360+ )
361+ self .tmp_containers .append (container .id )
362+ exec_output = container .exec_run ("sh -c 'exit 42'" )
363+ assert exec_output [0 ] == 42
364+
356365 def test_exec_run_failed (self ):
357366 client = docker .from_env (version = TEST_API_VERSION )
358367 container = client .containers .run (
359368 "alpine" , "sh -c 'sleep 60'" , detach = True
360369 )
361370 self .tmp_containers .append (container .id )
362- exec_output = container .exec_run ("docker ps" )
363- assert exec_output [0 ] == 126
371+ exec_output = container .exec_run ("non-existent" )
372+ # older versions of docker return `126` in the case that an exec cannot
373+ # be started due to a missing executable. We're fixing this for the
374+ # future, so accept both for now.
375+ assert exec_output [0 ] == 127 or exec_output [0 ] == 126
364376
365377 def test_kill (self ):
366378 client = docker .from_env (version = TEST_API_VERSION )
0 commit comments