GoogleContainerTools/skaffold · error

retrieving working dir for %q: %w

Error message

retrieving working dir for %q: %w

What it means

`syncItem` wraps failures from `WorkingDir(ctx, tag, cfg)`, which inspects the built image (e.g. via docker inspect) to learn its working directory. The error means skaffold could not retrieve the container working dir, so relative sync paths inside the container cannot be computed and the file sync item cannot be created.

Source

Thrown at pkg/skaffold/sync/sync.go:88

	switch {
	case len(a.Sync.Manual) > 0:
		return syncItem(ctx, a, tag, e, a.Sync.Manual, cfg)

	case a.Sync.Auto != nil:
		return autoSyncItem(ctx, a, tag, e, cfg)

	case len(a.Sync.Infer) > 0:
		return inferredSyncItem(ctx, a, tag, e, cfg)

	default:
		return nil, nil
	}
}

func syncItem(ctx context.Context, a *latest.Artifact, tag string, e filemon.Events, syncRules []*latest.SyncRule, cfg docker.Config) (*Item, error) {
	containerWd, err := WorkingDir(ctx, tag, cfg)
	if err != nil {
		return nil, fmt.Errorf("retrieving working dir for %q: %w", tag, err)
	}

	toCopy, err := intersect(ctx, a.Workspace, containerWd, syncRules, append(e.Added, e.Modified...))
	if err != nil {
		return nil, fmt.Errorf("intersecting sync map and added, modified files: %w", err)
	}

	toDelete, err := intersect(ctx, a.Workspace, containerWd, syncRules, e.Deleted)
	if err != nil {
		return nil, fmt.Errorf("intersecting sync map and deleted files: %w", err)
	}

	// Something went wrong, don't sync, rebuild.
	if toCopy == nil || toDelete == nil {
		return nil, nil
	}

	return &Item{Image: tag, Artifact: a, Copy: toCopy, Delete: toDelete}, nil

View on GitHub (pinned to a1189de023)

Solutions

  1. Verify the image with the given tag exists (docker images) and rebuild if it was pruned.
  2. Check DOCKER_HOST / docker daemon connectivity (docker info).
  3. Re-authenticate with the registry if image inspection requires remote metadata access.
  4. Trigger a full rebuild/redeploy to get a fresh, inspectable image tag.

Example fix

// before
export DOCKER_HOST=tcp://unreachable:2375
skaffold dev // retrieving working dir: cannot connect
// after
export DOCKER_HOST=unix:///var/run/docker.sock
skaffold dev // inspect succeeds
Defensive patterns

Strategy: validation

Validate before calling

if _, _, err := exec.Command("docker", "image", "inspect", tag).CombinedOutput(); err != nil {
  return fmt.Errorf("image %s missing locally; rebuild before sync", tag)
}

Try / catch

item, err := sync.NewItem(ctx, artifact, events, builds, cfg)
if err != nil {
  if strings.Contains(err.Error(), "retrieving working dir") {
    log.Printf("cannot inspect image (%v); falling back to rebuild", err)
    return triggerRebuild(artifact)
  }
  return err
}

Prevention

When it happens

Trigger: Calling `syncItem` (via `NewItem` or `autoSyncItem`) with a tag whose image no longer exists locally, a docker daemon that is unreachable, or an image without a resolvable Config.WorkingDir due to registry/inspect API errors.

Common situations: Docker image pruned between build and sync so `docker inspect` fails; DOCKER_HOST pointing at an unreachable remote daemon; registry authentication errors when the image must be inspected remotely; corrupted image metadata.

Related errors


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