GoogleContainerTools/skaffold · error

copying files: %w

Error message

copying files: %w

What it means

`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).

Source

Thrown at pkg/skaffold/sync/docker.go:39

	"fmt"
	"io"
	"os/exec"

	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
	"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util"
)

type ContainerSyncer struct{}

func NewContainerSyncer() *ContainerSyncer {
	return &ContainerSyncer{}
}

func (s *ContainerSyncer) Sync(ctx context.Context, _ io.Writer, item *Item) error {
	if len(item.Copy) > 0 {
		log.Entry(ctx).Info("Copying files:", item.Copy, "to", item.Image)
		if _, err := util.RunCmdOut(ctx, s.copyFileFn(ctx, item.Artifact.ImageName, item.Copy)); err != nil {
			return fmt.Errorf("copying files: %w", err)
		}
	}

	if len(item.Delete) > 0 {
		log.Entry(ctx).Info("Deleting files:", item.Delete, "from", item.Image)
		if _, err := util.RunCmdOut(ctx, s.deleteFileFn(ctx, item.Artifact.ImageName, item.Delete)); err != nil {
			return fmt.Errorf("deleting files: %w", err)
		}
	}

	return nil
}

func (s *ContainerSyncer) deleteFileFn(ctx context.Context, containerName string, files syncMap) *exec.Cmd {
	var args []string
	args = append(args, "exec", "-i", containerName, "rm", "-rf", "--")
	for _, dsts := range files {
		args = append(args, dsts...)

View on GitHub (pinned to a1189de023)

Solutions

  1. Check the target container is running (docker ps / kubectl get pods) and restart it if it exited.
  2. Verify the docker CLI/daemon is reachable and you have permission on /var/run/docker.sock.
  3. Save the file again or trigger a rebuild so a fresh sync Item with valid paths is generated.
  4. Confirm the image name in the sync Item matches the running container's image.

Example fix

// before (container exited, docker cp fails)
skaffold dev // file sync fails: copying files: exit status 1
// after
kubectl rollout restart deploy/myapp && skaffold dev // container healthy, sync works
Defensive patterns

Strategy: try-catch

Validate before calling

out, err := exec.Command("docker", "inspect", "-f", "{{.State.Running}}", imageName).Output()
if err != nil || strings.TrimSpace(string(out)) != "true" {
  return fmt.Errorf("container for %s is not running; skipping copy sync", imageName)
}

Try / catch

err := syncer.Sync(ctx, out, item)
if err != nil {
  if strings.Contains(err.Error(), "copying files") {
    log.Printf("copy sync failed (%v); falling back to full rebuild", err)
    return triggerRebuild(item.Artifact)
  }
  return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/1b561ab83c33ac15. Report an issue: GitHub.