@@ -23,7 +23,11 @@ def copy_between_containers(
2323):
2424 """
2525 Copy files from one Docker container to another via a temporary local directory.
26+
27+ Be extremely careful with trailing slashes in src_path and dest_path, the behavior
28+ of docker cp is also different depending on whether the destination exists.
2629 """
30+ print (f"Copy between containers: { src_path } -> { dest_path } " )
2731 with tempfile .TemporaryDirectory () as temp_dir :
2832 temp_path = Path (temp_dir ) / Path (src_path ).name
2933
@@ -66,6 +70,9 @@ def copy_to_container(
6670 Copy a file or directory from the local filesystem to a Docker container.
6771
6872 The copy operation is recursive for directories.
73+
74+ Be extremely careful with trailing slashes in src_path and dest_path, the behavior
75+ of docker cp is also different depending on whether the destination exists.
6976 """
7077 if not str (dest_path ).startswith ("/" ):
7178 # If not an absolute path, assume relative to container's cwd
@@ -76,6 +83,7 @@ def copy_to_container(
7683 str (src_path ),
7784 f"{ container .container_id } :{ dest_path } " ,
7885 ]
86+ print (f"Copy to container: cmd={ cmd } " )
7987 # Ensure destination folder exists
8088 assert_zero_exit_code (container .execute (f"mkdir -p { Path (dest_path ).parent } " ))
8189 result = subprocess .run (cmd , check = False , capture_output = True , text = True )
@@ -95,13 +103,17 @@ def copy_from_container(
95103 Copy a file or directory from a Docker container to the local filesystem.
96104
97105 The copy operation is recursive for directories.
106+
107+ Be extremely careful with trailing slashes in src_path and dest_path, the behavior
108+ of docker cp is also different depending on whether the destination exists.
98109 """
99110 cmd = [
100111 "docker" ,
101112 "cp" ,
102113 f"{ container .container_id } :{ src_path } " ,
103114 str (dest_path ),
104115 ]
116+ print (f"Copy from container: cmd={ cmd } " )
105117 Path (dest_path ).parent .mkdir (parents = True , exist_ok = True )
106118 result = subprocess .run (cmd , check = False , capture_output = True , text = True )
107119 if result .returncode != 0 :
0 commit comments