{"record":{"id":"1b561ab83c33ac15","repo":"GoogleContainerTools/skaffold","slug":"copying-files-w","errorCode":null,"errorMessage":"copying files: %w","messagePattern":"copying files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sync/docker.go","lineNumber":39,"sourceCode":"\t\"fmt\"\n\t\"io\"\n\t\"os/exec\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util\"\n)\n\ntype ContainerSyncer struct{}\n\nfunc NewContainerSyncer() *ContainerSyncer {\n\treturn &ContainerSyncer{}\n}\n\nfunc (s *ContainerSyncer) Sync(ctx context.Context, _ io.Writer, item *Item) error {\n\tif len(item.Copy) > 0 {\n\t\tlog.Entry(ctx).Info(\"Copying files:\", item.Copy, \"to\", item.Image)\n\t\tif _, err := util.RunCmdOut(ctx, s.copyFileFn(ctx, item.Artifact.ImageName, item.Copy)); err != nil {\n\t\t\treturn fmt.Errorf(\"copying files: %w\", err)\n\t\t}\n\t}\n\n\tif len(item.Delete) > 0 {\n\t\tlog.Entry(ctx).Info(\"Deleting files:\", item.Delete, \"from\", item.Image)\n\t\tif _, err := util.RunCmdOut(ctx, s.deleteFileFn(ctx, item.Artifact.ImageName, item.Delete)); err != nil {\n\t\t\treturn fmt.Errorf(\"deleting files: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (s *ContainerSyncer) deleteFileFn(ctx context.Context, containerName string, files syncMap) *exec.Cmd {\n\tvar args []string\n\targs = append(args, \"exec\", \"-i\", containerName, \"rm\", \"-rf\", \"--\")\n\tfor _, dsts := range files {\n\t\targs = append(args, dsts...)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sync/docker.go#L21-L57","documentation":"`ContainerSyncer.Sync` wraps failures from running the copy command (`s.copyFileFn`, typically `docker cp`/`kubectl cp` style) used to hot-sync modified/added files into a running container. It means new or changed files could not be copied into the container, so the incremental sync is aborted (usually falling back to a rebuild).","triggerScenarios":"Calling `Sync` with an `Item` whose `Copy` list is non-empty while the target container is stopped/restarted, the image name doesn't match a running container, the CLI binary is missing, or the files being copied no longer exist in the workspace.","commonSituations":"Container crashed or was redeployed between file save and sync; docker not running or permission denied on the docker socket; syncing into a container that exited due to a hot-reload crash; file path changed on the host after the sync item was computed.","solutions":["Check the target container is running (docker ps / kubectl get pods) and restart it if it exited.","Verify the docker CLI/daemon is reachable and you have permission on /var/run/docker.sock.","Save the file again or trigger a rebuild so a fresh sync Item with valid paths is generated.","Confirm the image name in the sync Item matches the running container's image."],"exampleFix":"// before (container exited, docker cp fails)\nskaffold dev // file sync fails: copying files: exit status 1\n// after\nkubectl rollout restart deploy/myapp && skaffold dev // container healthy, sync works","handlingStrategy":"try-catch","validationCode":"out, err := exec.Command(\"docker\", \"inspect\", \"-f\", \"{{.State.Running}}\", imageName).Output()\nif err != nil || strings.TrimSpace(string(out)) != \"true\" {\n  return fmt.Errorf(\"container for %s is not running; skipping copy sync\", imageName)\n}","typeGuard":null,"tryCatchPattern":"err := syncer.Sync(ctx, out, item)\nif err != nil {\n  if strings.Contains(err.Error(), \"copying files\") {\n    log.Printf(\"copy sync failed (%v); falling back to full rebuild\", err)\n    return triggerRebuild(item.Artifact)\n  }\n  return err\n}","preventionTips":["Keep the target container running during dev (use restart policies or stable hot-reload tooling).","Verify docker/kubectl CLI availability and daemon/socket permissions before dev.","Save files promptly; avoid editing while the container is being redeployed.","Fall back to rebuild-on-sync-failure rather than assuming sync succeeded."],"tags":["file-sync","docker","containers","go"],"backgroundTag":"container-file-sync-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}