Load environment from a file
Load variables from a file with docker run --env-file. The file is not parsed by a shell, so quotes stay in the value and a line with export fails.
A dozen variables belong in a file, and the file you already have for the application looks like shell syntax.
printf 'MODE=debug\nNAME="quoted"\n# a comment\nEMPTY=\n' > app.env
docker run --rm --env-file app.env alpine:3.20 sh -c 'echo "[$MODE] [$NAME] [$EMPTY]"'
printf 'export MODE=debug\n' > shell.env
docker run --rm --env-file shell.env alpine:3.20 sh -c 'env | grep -i mode'[debug] ["quoted"] []
docker: --env-file: invalid env file (shell.env): variable 'export MODE' contains whitespaces
Run 'docker run --help' for more informationThe --env-file format is one NAME=value per line, with # lines ignored, and the value is taken literally. The second variable shows the catch: the double quotes are part of the value, unlike in a Compose file or a shell script. The format is described in the docker run reference. A line that begins with export is rejected by the client, which reports that the variable name export MODE contains whitespace.
Leave the quotes out of the file, or use a Compose env_file, whose parser handles them. A bare name with no equals sign copies the variable from the host, as with -e. The file is read by the client at start, so later edits do not reach a running container.