Skip to content

[BUG] docker exec not printing any output under socket-proxy #10

@jonasgeiler

Description

@jonasgeiler

Note: All parts with EDIT N: have been added later on using information from the comments below.

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

For some reason when using the docker exec command with the proxy I don't get any output back. This only happens when I use linuxserver/socket-proxy:

# Using the original socket, file gets created and prints "Hello World" normally
$ DOCKER_HOST=unix:///var/run/docker.sock docker exec somecontainer sh -c 'echo Hello World | tee testsocket.txt'
Hello World

# Using linuxserver/socket-proxy, file gets created, but doesn't print anything???
$ DOCKER_HOST=tcp://socket-proxy-exec:2375 docker exec somecontainer sh -c 'echo Hello World | tee testproxy.txt'

# EDIT 3: Using tecnativa/docker-socket-proxy (which this project is based on), file gets created and prints "Hello World" normally
$ DOCKER_HOST=tcp://tecnativa-socket-proxy-exec:2375 docker exec somecontainer sh -c 'echo Hello World | tee testtecnativaproxy.txt'
Hello World

I have enabled literally every possible endpoint permission in the socket-proxy-exec container, so I don't think I'm missing something there.

EDIT 1: It does work as expected when passing the --interactive argument to docker exec:

$ DOCKER_HOST=tcp://socket-proxy-exec:2375 docker exec --interactive somecontainer sh -c 'echo Hello World | tee testproxy.txt'
Hello World

But you shouldn't have to do that. After all Tecnativa's docker-socket-proxy doesn't require it.

EDIT 2: After sniffing the HTTP traffic the only noticable difference between the direct connection to Docker / Tecnativa's docker-socket-proxy and linuxserver's socket-proxy is that in the response from GET /v1.46/exec/{id}/json the fields Running and ExitCode are different:

// Direct Docker connection / Tecnativa's docker-socket-proxy
HTTP/1.1 200 OK
{
  "Running": false,
  "ExitCode": 0,
  // ...
}

// linuxserver's socket-proxy
HTTP/1.1 200 OK
{
  "Running": true,
  "ExitCode": null,
  // ...
}

The reason is unknown. Presumably because the STDOUT pipe fails to open? See Docker daemon logs below.

EDIT 5: It seems like there is now a similar problem with the latest version of Tecnativa's docker-socket-proxy: Tecnativa/docker-socket-proxy#132
According to @Roxedus it is related to this issue, since it matches the findings regarding the hijack.

Expected Behavior

$ DOCKER_HOST=tcp://socket-proxy-exec:2375 docker exec somecontainer sh -c 'echo Hello World | tee testproxy.txt'
Hello World

Steps To Reproduce

  1. Start socket-proxy with:
    docker run --rm --name socket-proxy -e POST=1 -e EXEC=1 -e CONTAINERS=1 -e INFO=1 -v /var/run/docker.sock:/var/run/docker.sock:ro --read-only --tmpfs /run -p 2378:2375 lscr.io/linuxserver/socket-proxy:1.26.1
  2. In a second terminal, try running docker exec using the socket-proxy:
    DOCKER_HOST=tcp://localhost:2378 docker exec socket-proxy echo Hello World
  3. As a countercheck, try running docker exec WITHOUT using the socket-proxy:
    docker exec socket-proxy echo Hello World
    This should print "Hello World" as expected.

Environment

- OS: EndeavorOS (Arch Linux-based Linux Distro)
- Linux Version: 6.9.7
- How docker service was installed: yay -S docker
- Docker Info:
    Client:
     Version:    27.0.2
     Context:    default
     Debug Mode: false
     Plugins:
      buildx: Docker Buildx (Docker Inc.)
        Version:  0.15.1
        Path:     /usr/lib/docker/cli-plugins/docker-buildx
      compose: Docker Compose (Docker Inc.)
        Version:  2.28.1
        Path:     /usr/lib/docker/cli-plugins/docker-compose

Docker creation

docker run --rm --name socket-proxy -e POST=1 -e EXEC=1 -e CONTAINERS=1 -e INFO=1 -v /var/run/docker.sock:/var/run/docker.sock:ro --read-only --tmpfs /run -p 2378:2375 lscr.io/linuxserver/socket-proxy:1.26.1

Container logs

172.17.0.1 - - [02/Jul/2024:15:14:18 +0000] "HEAD /_ping HTTP/1.1" 200 0 "-" "Docker-Client/27.0.2 (linux)"
172.17.0.1 - - [02/Jul/2024:15:14:18 +0000] "GET /v1.46/containers/socket-proxy/json HTTP/1.1" 200 6297 "-" "Docker-Client/27.0.2 (linux)"
172.17.0.1 - - [02/Jul/2024:15:14:18 +0000] "POST /v1.46/containers/socket-proxy/exec HTTP/1.1" 201 74 "-" "Docker-Client/27.0.2 (linux)"
172.17.0.1 - - [02/Jul/2024:15:14:18 +0000] "POST /v1.46/exec/b471933ab0f89f404f0e0380ad945553da2197218e8b3bda235c1200aa5c0e39/start HTTP/1.1" 101 0 "-" "Docker-Client/27.0.2 (linux)"
172.17.0.1 - - [02/Jul/2024:15:14:18 +0000] "GET /v1.46/exec/b471933ab0f89f404f0e0380ad945553da2197218e8b3bda235c1200aa5c0e39/json HTTP/1.1" 200 375 "-" "Docker-Client/27.0.2 (linux)"

EDIT 4: Docker daemon logs

DEBU[2024-07-03T05:07:03.950660279+02:00] Calling HEAD /_ping
DEBU[2024-07-03T05:07:03.951248332+02:00] Calling GET /v1.46/containers/socket-proxy/json
DEBU[2024-07-03T05:07:03.952955791+02:00] Calling POST /v1.46/containers/socket-proxy/exec
DEBU[2024-07-03T05:07:03.953028291+02:00] form data: {"AttachStderr":true,"AttachStdin":false,"AttachStdout":true,"Cmd":["echo","Hi"],"Detach":false,"DetachKeys":"","Env":null,"Privileged":false,"Tty":false,"User":"","WorkingDir":""}
DEBU[2024-07-03T05:07:03.954046261+02:00] Calling POST /v1.46/exec/3aaa192d3a940508cc7cb665ae5c4ed65794929364887c58671ce231bd4d4068/start
DEBU[2024-07-03T05:07:03.954093599+02:00] form data: {"Detach":false,"Tty":false}
DEBU[2024-07-03T05:07:03.954201937+02:00] starting exec command 3aaa192d3a940508cc7cb665ae5c4ed65794929364887c58671ce231bd4d4068 in container 701651b0afdcc068edcf4286ce66087072195672a19a31771845d2cd7f2d262f
DEBU[2024-07-03T05:07:03.955190819+02:00] Calling GET /v1.46/exec/3aaa192d3a940508cc7cb665ae5c4ed65794929364887c58671ce231bd4d4068/json
DEBU[2024-07-03T05:07:03.956104406+02:00] attach: stdout: begin
DEBU[2024-07-03T05:07:03.956112521+02:00] attach: stderr: begin
DEBU[2024-07-03T05:07:03.957266663+02:00] event                                         module=libcontainerd namespace=moby topic=/tasks/exec-added
DEBU[2024-07-03T05:07:03.996514541+02:00] attach: stdout                                error="write unix /var/run/docker.sock->@: write: broken pipe"
DEBU[2024-07-03T05:07:03.996608812+02:00] attach: stdout: end
DEBU[2024-07-03T05:07:03.996915904+02:00] event                                         module=libcontainerd namespace=moby topic=/tasks/exec-started
DEBU[2024-07-03T05:07:03.996966565+02:00] event                                         module=libcontainerd namespace=moby topic=/tasks/exit
DEBU[2024-07-03T05:07:03.997014714+02:00] attach: stderr: end
DEBU[2024-07-03T05:07:03.997041415+02:00] attach done
ERRO[2024-07-03T05:07:03.997104052+02:00] Error running exec 3aaa192d3a940508cc7cb665ae5c4ed65794929364887c58671ce231bd4d4068 in container: exec attach failed: error attaching stdout stream: write unix /var/run/docker.sock->@: write: broken pipe

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions