From 0d5d7057adc59e59a9c48da17aa8b1e23ead31c7 Mon Sep 17 00:00:00 2001 From: Harold Sun Date: Sat, 14 Feb 2026 02:16:52 +0000 Subject: [PATCH] fix: move symlink restore to after container start Containerd/Finch resolves bind mounts at start time, not create time. Moving the symlink restore to after start() ensures the empty directory mountpoints are still present when the container runtime sets up mounts. --- samcli/local/docker/container.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/samcli/local/docker/container.py b/samcli/local/docker/container.py index d73b7dda7b5..76da451f41a 100644 --- a/samcli/local/docker/container.py +++ b/samcli/local/docker/container.py @@ -287,11 +287,6 @@ def create(self, context): raise DockerContainerCreationFailedException( f"Container creation failed: {ex.explanation}, check template for potential issue" ) - finally: - # Restore any symlinks that were temporarily replaced with directories - # for container mount compatibility. This ensures the host filesystem - # remains unchanged for subsequent invocations. - self._restore_mapped_symlinks() self.id = real_container.id # Output container ID for test parsing @@ -491,6 +486,11 @@ def start(self, input_data=None): if "Ports are not available" in str(ex): raise PortAlreadyInUse(ex.explanation.decode()) from ex raise ex + finally: + # Restore any symlinks that were temporarily replaced with directories + # during container creation for mount compatibility (Finch/containerd). + # Must happen after start() since containerd resolves mounts at start time. + self._restore_mapped_symlinks() def _initialize_concurrency_control(self): """