Skip to content

Conversation

@tensorworker
Copy link

@tensorworker tensorworker commented Jan 14, 2026

When using --env-file=/~.env, the tilde was not expanded to the user's home directory. Instead, it was treated as a literal character and resolved relative to the current working directory, resulting in errors like "couldn't find env file: /current/dir/~/.env".

This adds an ExpandUser function that expands ~ to the home directory before converting relative paths to absolute paths.
Fixes #13508

What I did

  • Added ExpandUser() function in internal/paths/paths.go that expands a leading ~ to the user's home directory using os.UserHomeDir()
  • Updated the env file path processing in cmd/compose/compose.go to call ExpandUser() before checking if paths are absolute
  • Added unit tests for the new function covering various edge cases (empty string, ~ only, ~/.env, ~/subdir/.env, absolute paths, relative paths, tilde in middle of path, ~otheruser/... syntax)

Related issue
Fixes #13508

@tensorworker tensorworker requested a review from a team as a code owner January 14, 2026 02:49
When using --env-file=~/.env, the tilde was not expanded to the user's
home directory. Instead, it was treated as a literal character and
resolved relative to the current working directory, resulting in errors
like "couldn't find env file: /current/dir/~/.env".

This adds an ExpandUser function that expands ~ to the home directory
before converting relative paths to absolute paths.

Fixes docker#13508

Signed-off-by: tensorworker <[email protected]>
@tensorworker tensorworker force-pushed the fix-env-file-tilde-expansion branch from 649fc90 to 59d599d Compare January 14, 2026 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] docker compose down --env does not translate ~/.env to .env file in home directory

1 participant