docker / docker/cli

Parameter expansion when using `docker run --env-file ....`

Open
#4,347 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug status/0-triage
Dominant language
Go
Stars
6.1k
Forks
2.2k
Avg merge
1d 15h
Merged PRs (30d)
43

Description

Description

Hi,
when running docker run --env-file env.list --rm ubuntu, parameter expansion is not applied to elements in env.list. The entry VAR=$USER is not expanded thus the env VAR will be assigned the literal string "$USER" in the container. This is inconsistant with the behavior of environment files when used with docker compose.

I hope this the correct repo and label. Sorry for any inconvenience.

Reproduce
  1. echo VAR=\$USER > env.list
  2. docker run --env-file env.list --rm -it ubuntu env | grep VAR
  3. => VAR=$USER
Expected behavior

The expected outcome should be the expanded value. In my case VAR=marvin. This would be in line with the behavior of docker compose.

services:
  test:
    image: "ubuntu"
    env_file:
      - ./env.list
    command: "bash -c 'env | grep VAR'"

docker compose -f docker-compose.yml up results in VAR=marvin

docker version
Client:
 Version:           24.0.2
 API version:       1.43
 Go version:        go1.20.4
 Git commit:        cb74dfc
 Built:             Thu May 25 21:51:00 2023
 OS/Arch:           linux/amd64
 Context:           default
docker info
Client:
 Version:    24.0.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.5
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.18.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
Additional Info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository file or test. Start by running the documented docker run --env-file reproduction and compare it with the docker compose example, then trace Docker CLI handling of --env-file. Done means shell-style parameter expansion produces the expected value in the container and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.