Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to get console mode for stdout: The handle is invalid. #8186

Closed
AnthonyMastrean opened this issue Mar 9, 2021 · 48 comments
Closed

failed to get console mode for stdout: The handle is invalid. #8186

AnthonyMastrean opened this issue Mar 9, 2021 · 48 comments
Assignees
Labels

Comments

@AnthonyMastrean
Copy link

Description of the issue

The docker-compose build command prints this failed error every time.

Context information (for bug reports)

Output of docker-compose version

docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.1c  28 May 2019

Output of docker version

Client: Docker Engine - Community
 Version:           20.10.2
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        2291f61
 Built:             Mon Dec 28 16:14:16 2020
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:15:28 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker-compose config
(Make sure to add the relevant -f and other flags)

services:
  web:
    build:
      context: C:\Users\anthony\example
      dockerfile: Dockerfile
version: '2.4'

and the Dockerfile can be anything, this works

FROM nginx:stable

Steps to reproduce the issue

  1. Create any Dockerfile on Windows
  2. Create any Docker Compose manifest with a build section pointing to the same Dockerfile
  3. Run docker-compose build

Observed result

The Docker Compose build command always prints the failed line. Nothing else seems to be wrong, but I'm not sure.

WARNING: Native build is an experimental feature and could change at any time
Building web
failed to get console mode for stdout: The handle is invalid.
[+] Building 0.1s (5/5) FINISHED
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 31B                                        0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/nginx:stable            0.0s
 => CACHED [1/1] FROM docker.io/library/nginx:stable                       0.0s
 => exporting to image                                                     0.0s
 => => exporting layers                                                    0.0s
 => => writing image sha256:b3914da1a942520904ff755103e5eb24c87fee1a5af36  0.0s
 => => naming to docker.io/library/downloads_web                           0.0s

Expected result

The plain Docker build command works as expected.

[+] Building 0.1s (5/5) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                            0.0s 
 => => transferring dockerfile: 31B                                                                                                                                                                             0.0s 
 => [internal] load .dockerignore                                                                                                                                                                               0.0s 
 => => transferring context: 2B                                                                                                                                                                                 0.0s 
 => [internal] load metadata for docker.io/library/nginx:stable                                                                                                                                                 0.0s 
 => CACHED [1/1] FROM docker.io/library/nginx:stable                                                                                                                                                            0.0s 
 => exporting to image                                                                                                                                                                                          0.0s 
 => => exporting layers                                                                                                                                                                                         0.0s 
 => => writing image sha256:b3914da1a942520904ff755103e5eb24c87fee1a5af365037b7fa48e38c6a16e                                                                                                                    0.0s 
 => => naming to docker.io/library/web                                          

Stacktrace / full error message

failed to get console mode for stdout: The handle is invalid.

Additional information

OS version / distribution, docker-compose install method, etc.

image

@AnthonyMastrean
Copy link
Author

I noticed this warning message only appears when running Docker Compose commands. It looks like both Docker and Docker Compose merged changes to use native build / buildx by default now. Why is this warning still here?

WARNING: Native build is an experimental feature and could change at any time

And why does the handle error disappear when I turn off native build?

PS> [System.Environment]::SetEnvironmentVariable('COMPOSE_DOCKER_CLI_BUILD', '0', 'Process')

PS> docker-compose build
Building web
Step 1/1 : FROM nginx:stable
 ---> 05f64a802c26

Successfully built 05f64a802c26
Successfully tagged downloads_web:latest

@ternavsky
Copy link

ternavsky commented Mar 10, 2021

Same for me. After yesterday update console output for docker-compose build changed. And it throws "failed to get console mode for stdout: The handle is invalid."

Windows 10
Docker Desktop 3.2.1

Fallback to Docker Desktop 3.1.0 helped

@JorisDebonnet
Copy link

I had the same issues since upgrading to 3.2.1 yesterday (on Windows 10). Aside of that failed message, my builds also seemed to hang on one specific line, so I also reverted to version 3.1.0.

Afterwards I figured that the line probably just takes a long time and it would actually have completed ... but 3.1.0 shows the console output I'm used to, which gives a more comfortable feeling: it's "clearly still doing stuff and not just hanging". So this does indeed feel like a serious issue.

(The screenshot in the OP confuses me a bit, because it shows 3.1.0, while the issue for ternavsky and I only appeared on 3.2.1.)

@xiaohuahou
Copy link

same issue.

@kalvintera
Copy link

same issue

@jehadassaf
Copy link

Same issue. Is there a way to prevent auto update?

@ternavsky
Copy link

ternavsky commented Mar 15, 2021

Same issue. Is there a way to prevent auto update?

I just deny Docker desktop to make changes in the system on startup. After that you should run Docker by yourself, cause autostart won't work. After a minute it continues to threat me that it will be updated on the next reboot)

@Myhael76
Copy link

I noticed this warning message only appears when running Docker Compose commands. It looks like both Docker and Docker Compose merged changes to use native build / buildx by default now. Why is this warning still here?

WARNING: Native build is an experimental feature and could change at any time

And why does the handle error disappear when I turn off native build?

PS> [System.Environment]::SetEnvironmentVariable('COMPOSE_DOCKER_CLI_BUILD', '0', 'Process')

PS> docker-compose build
Building web
Step 1/1 : FROM nginx:stable
 ---> 05f64a802c26

Successfully built 05f64a802c26
Successfully tagged downloads_web:latest

Same fore me. In normal command window this works:

set COMPOSE_DOCKER_CLI_BUILD=0
docoker-compose build

If I put the variable on 1 it gives the handle error.

I updated today, March 15th

c:\>docker-compose version
docker-compose version 1.28.5, build c4eb3a1f
docker-py version: 4.4.4
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

@sigmanil
Copy link

same issue.

@bc3tech
Copy link

bc3tech commented Mar 16, 2021

+1

@nunoperalta
Copy link

Great suggestion above.

In VS Code, I'm adding to the workspace settings:

	"terminal.integrated.env.windows": {
		"COMPOSE_DOCKER_CLI_BUILD": "0"
	},

The first time, VS Code will ask if you allow setting this variable, when you open the terminal.
Press "Allow", kill the terminal and restart the terminal.

"docker-compose build" will now work properly.

@aiordache aiordache self-assigned this Mar 17, 2021
@Warfront1
Copy link

Same issue on windows docker desktop 3.2.2.
image

The most upsetting part of this all is how docker just auto updated.
Previously I would wait numerous months after a update, to actually update my docker, to avoid these kind of small bugs.
I would typically update on another test development machine, prior to updating my actual development machine
to ensure there are no bugs on the latest version.
We really need a way to opt out of updates, as this can really kill productivity.

@icavalheiro
Copy link

This is actually driving me crazy, I have so many developers affected because of this...
Setting COMPOSE_DOCKER_CLI_BUILD to 0 actually breaks it (same error we get when docker service is not initialized).

@ZukkyBaig
Copy link

Any update on what's happening with this? It's happening to all of my developers, and it's obscuring the logs.

@tvaudelin
Copy link

Same problem on my side. It would be great to get an update.

@jski
Copy link

jski commented Apr 2, 2021

Having this same issue and interested in a solution as well.

@ndeloof ndeloof assigned ndeloof and unassigned aiordache Apr 6, 2021
@ndeloof
Copy link
Contributor

ndeloof commented Apr 6, 2021

@ndeloof
Copy link
Contributor

ndeloof commented Apr 6, 2021

I expected this could be fixed by running build with --progress=plain, but unfortunately error persists. There might be another piece of code using ConsoleFromFile :(

@Westmorland
Copy link

+1

@ro-anderson
Copy link

same issue.

@ChristophorusReyhan
Copy link

ChristophorusReyhan commented Apr 7, 2021

Same issue, docker-compose build stuck at

=> [stage-0 2/8] RUN apt-get update && apt-get install -y git 202.4s

after updating docker, and

failed to get console mode for stdout: The handle is invalid.

warning appears. COMPOSE_DOCKER_CLI_BUILD=0 doesn't solve the problem.

D:>docker-compose version
docker-compose version 1.28.5, build c4eb3a1
docker-py version: 4.4.4
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g 21 Apr 2020

It would be great if auto-update is an option.

@alexpapworth
Copy link

Fixed in docker-compose version 1.29.1, for those that want to cross-reference with docker-compose version.

@JeremyKennedy
Copy link

I can confirm that I don't get this error anymore. On Windows, I had to manually download the new compose binary and replace it on my system, since Docker for Windows didn't seem to be able to pull the most recent update.

@AlissonRS
Copy link

@JeremyKennedy I can confirm that too. Only solved after manually downloading the binary (link below) and replacing it manually.

https://github.com/docker/compose/releases

@shakyav
Copy link

shakyav commented Apr 24, 2021

@JeremyKennedy I can confirm that too. Only solved after manually downloading the binary (link below) and replacing it manually.

https://github.com/docker/compose/releases

How to replace docker-compose manually on windows ?

@AlissonRS
Copy link

@shakyav download the .exe from the link: https://github.com/docker/compose/releases

image

Replace the docker-compose.exe in your machine with the one you downloaded.

If you don't know where docker-compose.exe is located in your machine, open Git Bash, type which docker-compose, this command will reveal the folder where docker-compose is installed in your machine.

image

image

@SetTrend
Copy link

SetTrend commented May 18, 2021

Just like to add a way to search using standard tools of the operating system (i.e. PowerShell):

(Get-ChildItem Env:Path).Value.Split(';')
  | Where-Object { $_.IndexOf('Docker') -gt 0 }
  | ForEach-Object { Get-ChildItem -Path $_ -Include 'docker-compose.exe' -Recurse 2>$Null }

... returning:

   Directory: C:\Program Files\Docker\Docker\resources\bin

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          12.05.2021    23:38       10452224 docker-compose.exe

@buddha314
Copy link

I had this problem launching from PowerShell. However, when launching from WSL2 it built correctly.

@cw0102
Copy link

cw0102 commented Jun 8, 2021

This seems to be tangentially relayed to the docker-compose command being merged into the "docker" command, i.e. "docker compose up -d" vs "docker-compose up -d". Using the latter I was getting this error, but the former works.

@gebrouwe
Copy link

Got the same error "failed to get console mode for stdout: The handle is invalid." for the command "docker compose run --rm ".
The error disappears when I replace "docker compose" by: "docker-compose".

I am using Docker Desktop for Windows 10.

$ docker --version
Docker version 20.10.10, build b485636

$ docker-compose --version
docker-compose version 1.29.2, build 5becea4

@j-p-e
Copy link

j-p-e commented Apr 6, 2022

seconded - it's back with these on Win10
Docker version 20.10.13, build a224086
Docker Compose version v2.3.3

@sokraflex
Copy link

sokraflex commented Apr 22, 2022

Same here - getting the warning on Windows 11: failed to get console mode for stdin: The handle is invalid.
Docker version 20.10.14, build a224086
Docker Compose version v2.4.1

Warning appears every time when I run docker-compose up or docker-compose down.
COMPOSE_DOCKER_CLI_BUILD=0 doesn't help.

/EDIT: Confirmed in Ubuntu Linux as well.

@maximepel
Copy link

I'm having the same "issue" on Windows while running a shell script containing the command:
cat context.tar.xz | docker build - --tag "something:1.0"

But when I run the same script on macOS (Apple M1):
I don't get this issue at all

It seems that the Docker image builds anyway but this could be problematic as my container won't work when run from Windows built image...

@CollinAlpert
Copy link

I am experiencing the issue when piping a docker command (e.g. docker build) into tee.

@ndeloof
Copy link
Contributor

ndeloof commented Mar 31, 2023

@CollinAlpert try running com.docker.cli build | tee ... I wonder this is a side effect for legacy telemetry mechanism in Docker Desktop

@FlorentP42
Copy link

Getting the same error message except it's directly from docker build, not from docker-compose with versions:

Client:
 Cloud integration: v1.0.35-desktop+001     
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:36:24 2023
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.22.0 (117440)
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:45 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

When redirecting the output of a bat script to a file from regular Windows cmd:
Withing cmd:
build.bat
Works fine, display full output in cmd.

Withing cmd:
build.bat > out.txt
Executes everything, display full output in cmd but in out.txt logs stops after:

docker build . --progress=plain -f .\build_with_docker\Dockerfile -t some_project_options...
failed to get console mode for stdout: The handle is invalid.

Then continues logging after the execution of the docker command is complete.

@blueblakk
Copy link

blueblakk commented Aug 30, 2023

Same issue executing my git hooks with docker compose.

image

docker-compose version 1.29.2, build 5becea4c
docker-py version: 5.0.0
CPython version: 3.9.0
OpenSSL version: OpenSSL 1.1.1g  21 Apr 2020

@tewha
Copy link

tewha commented Sep 12, 2023

I only started getting this last week with Git for Windows' bash run through Windows Terminal.

I tee'd it to see the output (I hope):

Redirect turned out to show the same thing:

$ docker build -q . > hash

$ cat hash
failed to get console mode for stdout: The handle is invalid.
sha256:c7c0efb9f8895c8a9d41e630051d503dc31d1537bbdbd8fb7a0e0de6b58499d8

Update: Happens with both HyperVisor and WSL 2.

@entrptaher
Copy link

I am facing same in powershell.

No issue,

docker build -q .          
sha256:06e2720c9ad96e85cfb75b71b5e669a6d17026eaef3b6ed9b3d7583062a58969```

Having issue,

echo $(docker build -q .)       
failed to get console mode for stdout: The handle is invalid.
sha256:06e2720c9ad96e85cfb75b71b5e669a6d17026eaef3b6ed9b3d7583062a58969

Running this in the wsl (but not with docker desktop, directly installed with get.docker.com),

docker build -q .
sha256:02456f9476874d8e72b8e658fcfd774175ded1c4b40efd4b72c826fd16aa889b

echo $(docker build -q .)
sha256:02456f9476874d8e72b8e658fcfd774175ded1c4b40efd4b72c826fd16aa889b

Running inside wsl in docker desktop,

docker build -q .
sha256:bf899b8ae1802f3d4415c33343b66b1d636a41e9121f19dfabe93073859e76b4

echo $(docker build -q .) 
sha256:bf899b8ae1802f3d4415c33343b66b1d636a41e9121f19dfabe93073859e76b4

@jcmuel
Copy link

jcmuel commented Feb 8, 2024

Our Windows developer has the same problem on Windows 11:

  1. Docker: 4.27.1
  2. GitBash: 2.43.0, with the following non-standard options:
    a. "Use Windows' default console Window"
    b. "Enable experimental support for pseudo consoles"

The following docker command produced the same error message.

> docker ps -aqf "name=^our_image_name_here"
failed to get console mode for stdout: The handle is invalid.
10edc44cf0c3

We downgraded docker to version 4.26.1 and that also solved the issue for us.

@FlorentP42
Copy link

@AnthonyMastrean Would you mind reopening this issue? As it is clrearly still broken in the latest release so far...

@ndeloof
Copy link
Contributor

ndeloof commented Feb 8, 2024

@jcmuel please report this issue to github.com/docker/cli as you can reproduce with a plain docker ps ... command

@jcmuel
Copy link

jcmuel commented Feb 8, 2024

The issue is also discussed here: docker/for-win#13891

@ndeloof : Should I report it anyway also in docker/cli ?

@ndeloof
Copy link
Contributor

ndeloof commented Feb 8, 2024

nope, docker/for-win#13891 already has enough details AFAICT

@karimkod
Copy link

karimkod commented Feb 13, 2024

on pwsh the only way I tought of to get around this is by using Select-Object:

docker ps --filter "status=running" --filter "name=mongodb" -q | Select-Object -Skip 1

@quarky42
Copy link

quarky42 commented Mar 7, 2024

Docker Desktop 4.27.2 had this error. Docker Desktop 4.28.0 fixed this for me.
I was using volumes=$(docker volume ls -q) and getting the error stored in the variable as part of a larger script that removed all listed volumes but only if $volumes was defined / non-empty. (Using Git-Bash)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests