compose: Unknown encoding error in Windows with cp65001

docker-compose raise an error under PowerShell or cmd with code page 65001(UTF-8):

PS> chcp
Active code page: 65001
PS> docker-compose --version
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "C:\projects\compose\compose\cli\main.py", line 54, in main
  File "C:\projects\compose\compose\cli\docopt_command.py", line 23, in sys_dispatch
  File "C:\projects\compose\compose\cli\docopt_command.py", line 26, in dispatch
  File "C:\projects\compose\compose\cli\docopt_command.py", line 29, in parse
  File "C:\projects\compose\compose\cli\docopt_command.py", line 13, in docopt_full_help
  File "c:\projects\compose\venv\lib\site-packages\docopt.py", line 575, in docopt
  File "c:\projects\compose\venv\lib\site-packages\docopt.py", line 484, in extras
LookupError: unknown encoding: cp65001
docker-compose returned -1

$Env:PYTHONIOENCODING = 'utf-8' is no effect.

It works fine with cp932(Shift-JIS, Japanese default code page):

PS> chcp 932
現在のコード ページ: 932
PS> docker-compose --version
docker-compose version 1.6.0rc2, build a7636be

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 33
  • Comments: 37

Most upvoted comments

I was able to fix it by adding this line to my Powershell profile: source forum post [Console]::OutputEncoding = [System.Text.Encoding]::Default

This issue is not happening on Python 3.5 so it may be a good reason to start bundling this with Py3 instead of Py2?

I’m using Cmder (Conemu mod) which sets cp65001 by default in the environment variables.

Is there a workaround here we can use for now? What are the implications of changing it?

See if my blog post here leads you in the right direction. https://killerspaz.wordpress.com/2017/03/30/docker-outside-of-docker/

For VSCode run following [Console]::OutputEncoding = [System.Text.Encoding]::Default in console to fix.

I get this error when using the PowerShell Integrated Console in VS Code as well.

Works fine in a regular PowerShell window on the same machine.

If using ConEmu, I found removing chcp utf-8 from Startup > Environment seemed to do the trick for removing the warning, and doesn’t appear to be messing with any unicode characters.

Since updating docker today I have not been able to run docker-compose.

$ docker --version
Docker version 19.03.5, build 633a0ea

I found in ConEmu using mysis gitbash on Windows 10 i needed to add chcp.com 437 to my ConEmu Startup > Environment to get rid of the python debug info. It’s worth noting that 437 is the output i got when i ran chcp.com from the shell even before i added it to my environment.

This solution worked for me.

I rebooted my computer and the problem was fixed.

Workaround in steps:

  • Start -> Run -> cmd (no, really don’t use anything else - cmder, conemu, anything)
  • run chcp
  • copy the currently active code page (for example for Czech it’s 852)
  • run chcp [number] (e.g. chcp 852) in the shell that does not work

Cmder specific workaround if you don’t want to change behaviour of all of your consoles:

  • in Setings -> Tasks click the + button
  • name the new task docker for example
  • copy values from your preffered task
    • in my case:
      • Task parameters: /icon "%CMDER_ROOT%\cmder.exe"
      • Commands: cmd /k "%ConEmuDir%\..\init.bat" -new_console)
  • to the “Commands” textarea add && chcp [number] (in my case && chcp 852) to the end of each line that has a command
    • in my case there is only one line, but generally there can be more of them
  • open that console (by selecting in the drop down in the new console dialog) and use it for anything docker-related

Could we solve this with using docker stack instead of docker-compose?

I was able to ‘resolve’ this issue with a workaround, using the win-unicode-console package for Python with pip install win-unicode-console and then restarting the terminal application.

This issue will be fixed (for all use cases, like from inside WSL) once docker-compose is released with embedded Python3 as an option: https://github.com/docker/compose/issues/5063

This error occurs with the combination of Windows10 and the Quick Start Terminal without changing the code page to another one (e.g. 932) by running chcp.com [code page].

$ docker-compose version
docker-compose version 1.12.0, build ee0f34e1
docker-py version: 2.2.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.2j  26 Sep 2016

$ docker version
Client:
 Version:      17.04.0-ce
 API version:  1.28
 Go version:   go1.7.5
 Git commit:   4845c56
 Built:        Wed Apr  5 23:33:17 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.04.0-ce
 API version:  1.28 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   4845c56
 Built:        Wed Apr  5 18:45:47 2017
 OS/Arch:      linux/amd64
 Experimental: false

I found in ConEmu using mysis gitbash on Windows 10 i needed to add chcp.com 437 to my ConEmu Startup > Environment to get rid of the python debug info. It’s worth noting that 437 is the output i got when i ran chcp.com from the shell even before i added it to my environment.

I also confirmed that this problem exists/surfaces using vscode on a Windows machine when there are comments in the docker-compose file. I got a workaround which did the trick for me docker-compose pull | % ToString on my Powershell prompt within vscode. Thanks @mklement0 !

Ah that’s weird, I replied to an email with that asking how to get docker inside a container. It won’t let me delete it on my phone, will check when I’m back at a computer.

The supposed workaround, of running chcp 850 or chcp 437 has a terrible side effect: it starts messing up characters.

Example:

11:58:02 ~$ cmd.exe /c chcp 437 > /tmp/chcp 2>&1
11:58:06 ~$ sudo find / -iname "pkg.?config"
find: ΓÇÿ/mnt/c/$Recycle.Bin/S-1-5-18ΓÇÖ: Permission denied

11:58:12 ~$ cmd.exe /c chcp 65001 > /tmp/chcp 2>&1
11:58:19 ~$ sudo find / -iname "pkg.?config"
find: ‘/mnt/c/$Recycle.Bin/S-1-5-18’: Permission denied

11:58:23 ~$ docker-compose stop
Traceback (most recent call last):
  File "logging\__init__.py", line 872, in emit
LookupError: unknown encoding: cp65001
Logged from file main.py, line 74

I need cp65001, and I need docker-compose. There needs to be a better fix.

On Windows, this error occurs when console’s code page is 65001(UTF). For powershell, I change that to 936(Chinese) and it is solved. But for WSL, I can’t change the code page, so I’m out of luck here. Hope the upgrading to Py3 happens soon.

@tomasfejfar Are you saying to run docker-compose in nothing other than cmd.exe?

@tomasfejfar virtual cookie for you! That fixed my problem.