Description of the issue
Variables containing special characters coming from env file are not preserved
Context information (for bug reports)
Output of docker(-)compose version
Docker Compose version v2.0.0-rc.2
(Also, Output of docker-compose-v1 version)
docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1h 22 Sep 2020
Output of docker version
Client:
Cloud integration: 1.0.17
Version: 20.10.8
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:55:20 2021
OS/Arch: darwin/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:52:10 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Output of docker-compose config
(Make sure to add the relevant -f and other flags)
services:
main:
build:
context: ***/dollar
dockerfile: ***/dollar/Dockerfile
environment:
VARIABLE_0: $ax
VARIABLE_1: $ax
VARIABLE_2: $a$0$12$_x
VARIABLE_3: $ax
env_file:
- .env
networks:
default: null
networks:
default:
name: dollar_default
Steps to reproduce the issue
- Create a simple Dockerfile
FROM alpine:3.13.6
CMD env | grep VARIABLE
- Create a simple docker-compose.yml file that reads from an env file
version: '3'
services:
main:
build: .
env_file: .env
- Create a
.env file with the following content
VARIABLE_0=$a$0$12$_x
VARIABLE_1="$a$0$12$_x"
VARIABLE_2='$a$0$12$_x'
VARIABLE_3= $a$0$12$_x
Observed result
Some parts of the environment variables are missing:
- dollar signs preceding numeric value or underscore
- double quotes
- single quotes (seeming to preserve the rest, but they are missing)
- leading spaces
Indeed, docker-compose up --build produces
main_1 | VARIABLE_0=$ax
main_1 | VARIABLE_1=$ax
main_1 | VARIABLE_2=$a$0$12$_x
main_1 | VARIABLE_3=$ax
Expected result
As the documentation states
There is no special handling of quotation marks. This means that they are part of the VAL.
So I expect the original values to be preserved, including all "special" characters (' " $0 $_...).
As a consquence, from what I understand, docker-compose up --build should produce:
main_1 | VARIABLE_0=$a$0$12$_x
main_1 | VARIABLE_1="$a$0$12$_x"
main_1 | VARIABLE_2='$a$0$12$_x'
main_1 | VARIABLE_3= $a$0$12$_x
Additional information
For information, the v1 version of docker-compose produces (docker-compose-v1 up --build):
main_1 | VARIABLE_0=$a$0$12$_x
main_1 | VARIABLE_1=$a$0$12$_x
main_1 | VARIABLE_2=$a$0$12$_x
main_1 | VARIABLE_3=$a$0$12$_x
and docker-compose-v1 config:
services:
main:
build:
context: ***/dollar
environment:
VARIABLE_0: $$a$$0$$12$$_x
VARIABLE_1: $$a$$0$$12$$_x
VARIABLE_2: $$a$$0$$12$$_x
VARIABLE_3: $$a$$0$$12$$_x
version: '3'
Which is not exactly the expected result either (quotes and leading spaces are NOT being preserved), but seems more reasonable when it comes to dollar signs.
Documentation issue
Whether it is chosen to preserve or not quotation marks or special characters (including spaces), I think it would be important that the documentation reflects the actual behaviour.
Description of the issue
Variables containing special characters coming from env file are not preserved
Context information (for bug reports)
docker compose ...docker-compose ...Output of
docker(-)compose version(Also, Output of
docker-compose-v1 version)Output of
docker versionOutput of
docker-compose config(Make sure to add the relevant
-fand other flags)Steps to reproduce the issue
.envfile with the following contentObserved result
Some parts of the environment variables are missing:
Indeed,
docker-compose up --buildproducesExpected result
As the documentation states
So I expect the original values to be preserved, including all "special" characters (
' " $0 $_...).As a consquence, from what I understand,
docker-compose up --buildshould produce:Additional information
For information, the v1 version of docker-compose produces (
docker-compose-v1 up --build):and
docker-compose-v1 config:Which is not exactly the expected result either (quotes and leading spaces are NOT being preserved), but seems more reasonable when it comes to dollar signs.
Documentation issue
Whether it is chosen to preserve or not quotation marks or special characters (including spaces), I think it would be important that the documentation reflects the actual behaviour.