compose: TypeError: environment can only contain strings when using run with .env file
Description of the issue
docker-compose run
fails to run when non-empty “.env” file is present, printing TypeError: environment can only contain strings
. docker-compose up
works correctly.
This started happening when I upgraded today from older Docker Desktop release with docker-compose 1.24.0.
Context information (for bug reports)
Output of docker-compose version
docker-compose version 1.25.2, build 698e2846
docker-py version: 4.1.0
CPython version: 2.7.16
OpenSSL version: OpenSSL 1.0.2q 20 Nov 2018
Output of docker version
Client: Docker Engine - Community
Version: 19.03.5
API version: 1.40
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:22:37 2019
OS/Arch: windows/amd64
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 19.03.5
API version: 1.40 (minimum version 1.12)
Go version: go1.12.12
Git commit: 633a0ea
Built: Wed Nov 13 07:29:19 2019
OS/Arch: linux/amd64
Experimental: true
containerd:
Version: v1.2.10
GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
runc:
Version: 1.0.0-rc8+dev
GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
docker-init:
Version: 0.18.0
GitCommit: fec3683
Output of docker-compose config
services:
ubuntu:
image: ubuntu:bionic
version: '2.1'
Steps to reproduce the issue
- Create docker-compose.yml file:
version: '2.1'
services:
ubuntu:
image: ubuntu:bionic
- Create .env file:
A=a
(I made sure that it contains only these three characters, i.e. 41 3D 61
)
3. Run docker-compose run ubuntu
- fails with “TypeError: environment can only contain strings”. Removing/emptying this file letsdocker-compose to run correctly.
Observed result
Fails to start
Expected result
Runs container using environment variables from .env
Stacktrace / full error message
Traceback (most recent call last):
File "docker-compose", line 6, in <module>
File "compose\cli\main.py", line 72, in main
File "compose\cli\main.py", line 128, in perform_command
File "compose\cli\main.py", line 865, in run
File "compose\cli\main.py", line 1349, in run_one_off_container
File "compose\cli\main.py", line 1469, in call_docker
File "subprocess.py", line 172, in call
File "subprocess.py", line 394, in __init__
File "subprocess.py", line 644, in _execute_child
TypeError: environment can only contain strings
[19220] Failed to execute script docker-compose
Additional information
OS: Windows 10 Pro 1909 (18363.592) - up to date docker-compose from Docker Desktop (stable, 2.2.0.0 42247).
Result is the same regardless of used shell: Power Shell / bash from Git for Windows / cmd
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 61
- Comments: 32
OK, I got workaround using earlier docker-compose v1.24.1 while awaiting a fix for Docker Desktop
Steps:
Download docker-compose v1.24.1 please looking for the file docker-compose-Windows-x86_64.exe from this tag https://github.com/docker/compose/releases/tag/1.24.1
Rename docker-compose-Windows-x86_64.exe to docker-compose.exe
Place docker-compose.exe anywhere in your working environement e.g.
E:\dev\docker-compose\docker-compose.exe
Override docker-compose v1.25.2 shipped with Docker Desktop using older version of docker-compose (v1.24.1) by going to Windows Environment Variables / System variables / Path as screenshot
please ensure e:\dev\docker-compose comes before C:\Program Files\Docker\Docker\resources\bin
Go to cmd and test if docker-compose v1.24.1 is literally active
Phew! the issue
TypeError: environment can only contain strings
is goneFixed by https://github.com/docker/compose/pull/7183
You can find a new release with the fix at https://github.com/docker/compose/releases/tag/1.25.3
Confirm same issue.
Confirmed after upgrade to Docker Desktop for Windows 2.2.0.0.
Workaround worked: Replaced docker-compose.exe v 1.25.2 with v 1.24.1 in C:\Program Files\Docker\Docker\resources\bin
In my case in my PATH I didn’t have
C:\Program Files\Docker\Docker\resources\bin
, so I did the old hack of renaming newdocker-compose.exe
todocker-compose-1.25.exe
and paste thedocker-compose-Windows-x86_64.exe
asdocker-compose.exe
. Everything works like before 😃Thanks for the tip @atthakorn !
This issue also happened on my side, the workaround i use is by SSH into the containers directly using
docker
command, not to be confused withdocker-compose
.Example: Usually i use command
The workaround i use is
My case, it happens on Windows CMD after upgraded the Docker desktop to v2.2.0.0 (42247) with docker compose v1.25.2 this morning
docker-compose exec container bash
Here is stack trace
However, when use docker-compose v1.24.1 in WSL against docker desktop v2.2.0.0 (42247), it runs succesfully.
Same issue.
Got it to work for me by following steps 1 & 2 from the quoted answer below. then for step 3 what I did was to go to
C:\Program Files\Docker\Docker\resources\bin
, made a backup copy of existingdocker-compose.exe
, then pasted the file from step 2 (the one that’sv1.24.1
)after that,
docker-compose
works again:Also confirming this error for any exec interaction with containers, replacing the docker-compose with 1.24.1 in C:\Program Files\Docker\Docker\resources\bin as sugested by @atthakorn and @mstellingwerff fixed the issue for the time being.
@gamenic-ramesh try this, or download the 1.24.1 tag… download—> Last release: https://github.com/docker/compose/releases/tag/1.25.3 overwrite—> C:\Program Files\Docker\Docker\resources\bin
The same problem on MAC
Same issue.
Thanks, I’ve found a root problem already. Seem like my .env contain some environment key without a value.
@z3niths Could you please open a new issue including your
docker-compose.yml
and all the environment files, including the.env
? From the feedback here, the issue is solved by1.25.3
. Note that a even newer release (1.25.4
) is available with a fix on environment variables with no value. Maybe that’s your issue.I override the docker-compose.exe with this release in this folder (Win10), and it’s working: C:\Program Files\Docker\Docker\resources\bin Last release: https://github.com/docker/compose/releases/tag/1.25.3
Same issue for me when using docker-compose via pycharm. Windows docker 19.03.5 Compose v1.25.2.
Oh, it seems that while I was trying to work around this and preparing my bug report somebody already did that in https://github.com/docker/for-win/issues/5517