IssueRaiser

Handle quotes in --env-file values consistently with Linux/WSL2 "source"ing

Hi there, I use a `.env` file to supply env vars for my application both when running locally and in a Docker container. When running my application in Linux/WSL2 (Ubuntu), I `source` the `.env` file before running. Example: ``` set -o allexport source ./myVars.env set +o allexport ``` And when running my application in Docker Desktop on Windows I use the --env-file option to specify the `.env` file: ``` docker run --env-file .\myVars.env <etc> ``` Unfortunately, some of the env var values in the `.env` file need to contain spaces. This means they must be double-quoted to work correctly when `source`ing in Linux. However when quoted, the parsing in `docker run` does not remove the quotes making the values invalid as they contain literal quote marks at beginning and end. The consequence of this is I need to maintain a second (mostly duplicate) `.env` file for Docker use. I would much prefer if `docker run` could parse `.env` files in the same way as my Linux `source`ing does and in line with the general shell concept that quotes are a guide to how a string should be interpreted - not part of the string itself. From searching, it seems this has been fixed in `docker compose` (https://github.com/docker/compose/issues/8388). Please can you also fix it in `docker run`?

Posted by markm77 on May 21, 2022, 1:54 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,500 issues0 comments

github (Sysadmin)

Handle quotes in --env-file values consistently with Linux/WSL2 "source"ing

markm77May 21, 2022, 1:54 PM

Hi there, I use a `.env` file to supply env vars for my application both when running locally and in a Docker container. When running my application in Linux/WSL2 (Ubuntu), I `source` the `.env` file before running. Example: ``` set -o allexport source ./myVars.env set +o allexport ``` And when running my application in Docker Desktop on Windows I use the --env-file option to specify the `.env` file: ``` docker run --env-file .\myVars.env <etc> ``` Unfortunately, some of the env var values in the `.env` file need to contain spaces. This means they must be double-quoted to work correctly when `source`ing in Linux. However when quoted, the parsing in `docker run` does not remove the quotes making the values invalid as they contain literal quote marks at beginning and end. The consequence of this is I need to maintain a second (mostly duplicate) `.env` file for Docker use. I would much prefer if `docker run` could parse `.env` files in the same way as my Linux `source`ing does and in line with the general shell concept that quotes are a guide to how a string should be interpreted - not part of the string itself. From searching, it seems this has been fixed in `docker compose` (https://github.com/docker/compose/issues/8388). Please can you also fix it in `docker run`?

Comments (0)

No comments yet. Start the discussion.

Comment on this issue