How to include special character (e.g. '=') as part of variable value in docker-compose .env file?

As per docker docs, environment variables in .env file expected to be in in key-val format as VAR=VAL which works fine for sample like foo=bar but no mention of unavoidable special characters e.g. '=', which may confuse for key-val separator OR space both part of valid db connection string as in:

secrets.env file:

 connectionString=Data Source=some-server;Initial Catalog=db;User ID=uid;Password=secretpassword

which is referred in docker-compose.debug.yaml file content as:

    container_name: "service-name"
      - secrets.env
      - "80:80"

Which is further used to transform into docker-compose.yaml as shown complete flow below:

enter image description here

So the question is - how do you include connection string which has = and Spaces as part of value ?

Need - We have few micro-services within VS solution and looking forward to avoid repetition of same connection strings otherwise needs in service spec of `docker-compose.yaml'

Tried including values in single/double quote but post transformation whatever after = is treated as value including quotes just similar like kubernets yaml file convention


1 Answers How to include special character (e.g. '=') as part of variable value in docker-compose .env file?

I ran a test without any issues:

$ cat .env

$ cat docker-compose.env.yml
version: '2'

    image: busybox
    command: env
      - SPECIAL

$ docker-compose -f docker-compose.env.yml up
Creating network "test_default" with the default driver
Creating test_test_1_55eac1c3767c ... done
Attaching to test_test_1_d7787ac5bfc0
test_1_d7787ac5bfc0 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
test_1_d7787ac5bfc0 | HOSTNAME=d249a16a8e09
test_1_d7787ac5bfc0 | SPECIAL=field=with=equals;and;semi-colons
test_1_d7787ac5bfc0 | HOME=/root
test_test_1_d7787ac5bfc0 exited with code 0

1 weeks ago