compose icon indicating copy to clipboard operation
compose copied to clipboard

Docker Desktop for Windows Stable 2.2.0.0 - docker-compose exec Unicode errors

Open g-thomasr opened this issue 6 years ago • 16 comments

  • [x] I have tried with the latest version of my channel (Stable or Edge)
  • [ ] I have uploaded Diagnostics
  • Diagnostics ID:

Expected behavior

docker-compose.exe behaves as it did in Docker Desktop for Windows 2.1.0.5.

Actual behavior

If terminal code page is UTF-8, docker-compose exec fails with LookupError: unknown encoding: cp65001 If .env file contains any entries, docker-compose exec fails with TypeError: environment can only contain strings

Information

  • Windows Version: Windows 10 Pro, build 18363.592
  • Docker Desktop Version: 2.2.0.0
  • Are you running inside a virtualized Windows e.g. on a cloud server or on a mac VM: No

The bundled docker-compose.exe appears to have been compiled using Python 2.7 and an older version of python-dotenv.

The issue can be worked around by installing docker-compose via pip and Python 3

Steps to reproduce the behavior

  1. Add docker-compose.yml:

     version: "3"
     services:
       test:
         image: ubuntu
         command: tail -f /dev/null
    
  2. Add .env:

     A=
    
  3. In powershell, run:

     $OutputEncoding = `
       [Console]::OutputEncoding = `
       [Console]::InputEncoding = [Text.Encoding]::UTF8
     chcp.com 65001
     docker-compose down
     docker-compose up -d test
     docker-compose exec test echo 1
    
  4. Observe unexpected error:

     Traceback (most recent call last):
       File "logging\__init__.py", line 879, in emit
       File "site-packages\colorama\ansitowin32.py", line 41, in write
       File "site-packages\colorama\ansitowin32.py", line 162, in write
       File "site-packages\colorama\ansitowin32.py", line 187, in write_and_convert
       File "site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
     LookupError: unknown encoding: cp65001
     Logged from file main.py, line 78
    
  5. Switch codepage to Windows 1252 and try again:

     $OutputEncoding = `
       [Console]::OutputEncoding = `
       [Console]::InputEncoding = [Text.Encoding]::GetEncoding(1252)
     chcp 1252
     docker-compose exec test echo 1
    
  6. Observe error:

     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 491, in exec_command
       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
     [8940] Failed to execute script docker-compose
    
  7. Remove .env and try again:

     rm .env
     docker-compose down
     docker-compose up -d test
     docker-compose exec test echo 1
    
  8. Observe expected output: 1

g-thomasr avatar Jan 21 '20 19:01 g-thomasr

@gurutech-thomasr thanks for the report and the detailed repro instructions. It fails as you describe on my local machine too.

djs55 avatar Jan 21 '20 20:01 djs55

docker-compose.exe --version (WSL Windows 10) Traceback (most recent call last): File "docker-compose", line 6, in File "compose\cli\main.py", line 71, in main File "compose\cli\main.py", line 103, in dispatch File "compose\cli\docopt_command.py", line 25, in parse File "compose\cli\docopt_command.py", line 12, in docopt_full_help File "site-packages\docopt.py", line 575, in docopt File "site-packages\docopt.py", line 484, in extras File "site-packages\colorama\ansitowin32.py", line 41, in write File "site-packages\colorama\ansitowin32.py", line 162, in write File "site-packages\colorama\ansitowin32.py", line 190, in write_and_convert File "site-packages\colorama\ansitowin32.py", line 195, in write_plain_text LookupError: unknown encoding: cp0 [2456] Failed to execute script docker-compose

akulyk avatar Jan 21 '20 21:01 akulyk

In the meantime while waiting a fix, please check out workaround here https://github.com/docker/compose/issues/7169#issuecomment-576987766

atthakorn avatar Jan 22 '20 03:01 atthakorn

Same here:

Traceback (most recent call last):
  File "docker-compose", line 6, in <module>
  File "compose\cli\main.py", line 71, in main
  File "compose\cli\main.py", line 103, in dispatch
  File "compose\cli\docopt_command.py", line 25, in parse
  File "compose\cli\docopt_command.py", line 12, in docopt_full_help
  File "site-packages\docopt.py", line 575, in docopt
  File "site-packages\docopt.py", line 484, in extras
  File "site-packages\colorama\ansitowin32.py", line 41, in write
  File "site-packages\colorama\ansitowin32.py", line 162, in write
  File "site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
  File "site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
LookupError: unknown encoding: cp65001
[18308] Failed to execute script docker-compose

polys avatar Jan 22 '20 15:01 polys

I'm also experiencing this and getting the following output repeatedly:

Traceback (most recent call last):
  File "logging\__init__.py", line 879, in emit
  File "site-packages\colorama\ansitowin32.py", line 41, in write
  File "site-packages\colorama\ansitowin32.py", line 162, in write
  File "site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
  File "site-packages\colorama\ansitowin32.py", line 195, in write_plain_text
LookupError: unknown encoding: cp65001
Logged from file service.py, line 578

andrewbanchich avatar Jan 22 '20 15:01 andrewbanchich

Same here since last update: docker-compose version Traceback (most recent call last): File "docker-compose", line 6, in File "compose\cli\main.py", line 72, in main File "compose\cli\main.py", line 117, in perform_command File "compose\cli\main.py", line 1134, in version File "site-packages\colorama\ansitowin32.py", line 41, in write File "site-packages\colorama\ansitowin32.py", line 162, in write File "site-packages\colorama\ansitowin32.py", line 190, in write_and_convert File "site-packages\colorama\ansitowin32.py", line 195, in write_plain_text LookupError: unknown encoding: cp65001 [19344] Failed to execute script docker-compose

ijaouani avatar Jan 22 '20 16:01 ijaouani

my workaround is chcp 437 before docker-compose on 2.2.0.

guitarrapc avatar Jan 22 '20 19:01 guitarrapc

Just using Git Bash fixes it too.

andrewbanchich avatar Jan 22 '20 20:01 andrewbanchich

Just using Git Bash fixes it too.

does not work for me.

liayn avatar Jan 22 '20 22:01 liayn

In case it gets buried, I worked around the issue by installing docker-compose via python 3.8 and pip:

> where.exe docker-compose.exe;  docker-compose version
C:\Program Files\Docker\resources\bin\docker-compose.exe
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

> $env:path = "C:\bin\python\38;C:\bin\python\38\Scripts;${env:path}"

> pip --version; pip install docker-compose
pip 20.0.1 from c:\bin\python\38\lib\site-packages\pip (python 3.8)

> where.exe docker-compose.exe; docker-compose version
C:\bin\Python\38\Scripts\docker-compose.exe
C:\Program Files\Docker\resources\bin\docker-compose.exe
docker-compose version 1.25.2, build unknown
docker-py version: 4.1.0
CPython version: 3.8.1
OpenSSL version: OpenSSL 1.1.1d  10 Sep 2019

The important bit is to ensure that the PATH environment variable prefers pip-installed docker-compose over the one installed with Docker Desktop for Windows.

Again, I suspect these related issues may be due to Docker Desktop for Windows bundling a docker-compose built for Python 2.7

g-thomasr avatar Jan 22 '20 22:01 g-thomasr

Fixed 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

ulyssessouza avatar Jan 23 '20 21:01 ulyssessouza

When can we expect an update to Docker Desktop with updated Docker Compose? Is there a recommended method of updating Docker Compose in Windows without janky hacks like copying over the top of the exe?

cardonator avatar Jan 24 '20 00:01 cardonator

Fixed by #7183

You can find a new release with the fix at https://github.com/docker/compose/releases/tag/1.25.3

I can confirm that docker-compose 1.25.3 fixed the problem. I worked around it by cinst -y docker-compose and making sure the chocolatey shims are placed before Docker-Desktop in PATH, .i.e.

  • C:\ProgramData\chocolatey\bin before
  • C:\Program Files\Docker\Docker\resources\bin

mkoertgen avatar Jan 28 '20 11:01 mkoertgen

I ensured that the Chocolatey path was listed before the actual Docker installation and also ensured that I had installed the latest version. Unfortunately, the error still occurs.

PS E:\cloud.ingwie.io\Work\Maria\elch-flohmarkt.laradock> docker-compose --version
docker-compose version 1.25.2, build 698e2846
PS E:\cloud.ingwie.io\Work\Maria\elch-flohmarkt.laradock> docker-compose exec workspace bash
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 491, in exec_command
  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
[26840] Failed to execute script docker-compose

Any other idea?

IngwiePhoenix avatar Jan 31 '20 08:01 IngwiePhoenix

@IngwiePhoenix Read above:

docker-compose 1.25.3 fixed the problem

liayn avatar Jan 31 '20 09:01 liayn

For me I had following error in .env file . Following fix worked for me. CHROME_HTTP_PROXY => CHROME_HTTP_PROXY=value

kumargaf avatar Oct 26 '22 17:10 kumargaf