docker/compose · error

operation cancelled by user

Error message

operation cancelled by user

What it means

Compose interactively lists the variables it is about to interpolate and asks 'Do you want to proceed with these variables? [Y/n]'. Answering 'n' (or anything not accepted as confirmation) makes the code return this sentinel error, aborting the command before the project is loaded.

Source

Thrown at cmd/compose/options.go:172

		return err
	}

	if noVariables {
		return nil
	}

	displayInterpolationVariables(dockerCli.Out(), varsInfo)

	// Prompt for confirmation
	userInput := prompt.NewPrompt(dockerCli.In(), dockerCli.Out())
	msg := "\nDo you want to proceed with these variables? [Y/n]: "
	confirmed, err := userInput.Confirm(msg, true)
	if err != nil {
		return err
	}

	if !confirmed {
		return fmt.Errorf("operation cancelled by user")
	}

	return nil
}

func extractInterpolationVariablesFromModel(ctx context.Context, dockerCli command.Cli, projectOptions *ProjectOptions, cmdEnvs []string) ([]varInfo, bool, error) {
	cmdEnvMap := types.NewMappingWithEquals(cmdEnvs).ToMapping()

	// Create a model without interpolation to extract variables
	opts := configOptions{
		noInterpolate:  true,
		ProjectOptions: projectOptions,
	}

	model, err := opts.ToModel(ctx, dockerCli, nil, cli.WithoutEnvironmentResolution, cli.WithLoadOptions(loader.WithSkipValidation))
	if err != nil {
		return nil, false, err
	}

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Answer 'Y' at the prompt if the proposed variable values are correct.
  2. Provide the missing variables via .env, --env-file, or exported environment so the prompt never appears.
  3. In automation, run with `-q`/non-interactive settings or pre-create the .env file rather than relying on the prompt.

Example fix

# before
cp env.example .env  # incomplete copy, prompt appears, user answers n

# after
# fill required vars first
cp env.example .env && ${EDITOR:-vi} .env
docker compose up
Defensive patterns

Strategy: fallback

Validate before calling

# bash: ensure all required vars are set so the prompt never appears
missing=0
for v in $(grep -oP '^\w+' .env.example 2>/dev/null); do
  [ -n "${!v:-}" ] || { echo "missing env: $v" >&2; missing=1; }
done
[ "$missing" = 0 ] || exit 2

Try / catch

if ! docker compose up -d 2>&1 | tee /dev/stderr | grep -q 'operation cancelled by user'; then :; else echo 'user declined interpolation vars — check .env' >&2; exit 2; fi

Prevention

When it happens

Trigger: Running a compose command in interactive mode where unresolved interpolation variables are detected (e.g. missing .env entries), then declining the confirmation prompt; or a non-terminal stdin feeding something other than 'y' so the prompt defaults are not confirmed.

Common situations: First run of a cloned project without a .env file; CI jobs where stdin is closed and the prompt reads EOF/no; users spooked by the variable listing and aborting intentionally.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/3443fd71d30fe8a7. Report an issue: GitHub.