根据docker文档,.env文件中的环境变量应该以key = val格式表示为VAR = VAL,对于像foo = bar这样的样本可以正常工作,但是没有提到不可避免的特殊字符,例如’=’,…
我没有任何问题地进行了测试:
$ cat .env ENV=default USER_NAME=test2 SPECIAL=field=with=equals;and;semi-colons $ cat docker-compose.env.yml version: '2' services: test: image: busybox command: env environment: - 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