@@ -59,7 +59,7 @@ def __init__(self):
59
59
self ._api_version = DOCKER_MINIMUM_API_VERSION
60
60
61
61
@staticmethod
62
- def install_busybox ():
62
+ async def install_busybox ():
63
63
64
64
if not sys .platform .startswith ("linux" ):
65
65
return
@@ -69,10 +69,24 @@ def install_busybox():
69
69
for busybox_exec in ("busybox-static" , "busybox.static" , "busybox" ):
70
70
busybox_path = shutil .which (busybox_exec )
71
71
if busybox_path :
72
- log .info (f"Installing busybox from '{ busybox_path } '" )
73
72
try :
74
- shutil .copy2 (busybox_path , dst_busybox , follow_symlinks = True )
75
- return
73
+ # check that busybox is statically linked
74
+ # (dynamically linked busybox will fail to run in a container)
75
+ proc = await asyncio .create_subprocess_exec (
76
+ "ldd" ,
77
+ busybox_path ,
78
+ stdout = asyncio .subprocess .PIPE ,
79
+ stderr = asyncio .subprocess .DEVNULL
80
+ )
81
+ stdout , _ = await proc .communicate ()
82
+ if proc .returncode == 1 :
83
+ # ldd returns 1 if the file is not a dynamic executable
84
+ log .info (f"Installing busybox from '{ busybox_path } ' to '{ dst_busybox } '" )
85
+ shutil .copy2 (busybox_path , dst_busybox , follow_symlinks = True )
86
+ return
87
+ else :
88
+ log .warning (f"Busybox '{ busybox_path } ' is dynamically linked\n "
89
+ f"{ stdout .decode ('utf-8' , errors = 'ignore' ).strip ()} " )
76
90
except OSError as e :
77
91
raise DockerError (f"Could not install busybox: { e } " )
78
92
raise DockerError ("No busybox executable could be found" )
0 commit comments