Skip to content

Unable to capture exec output to file or variable in bash #9104

@gchamon

Description

@gchamon

Description

It used to be possible to just capture a docker-compose exec output and manipulate it later. Now even pipes in bash completely breaks because the command is not outputting to stdout anymore, and piping stderr to stdout doesn't work as a workaround.

Steps to reproduce the issue:

  1. We need a persistent docker-compose.yml service, so I will just use nginx for this purpose:
version: "3"

services:
  nginx:
    image: nginx
  1. docker-compose up -d nginx
  2. Try to capture the output of an execution in the running container fails, for instance docker-compose exec nginx echo true | grep false will output true.

Describe the results you received:

It is impossible to capture the output of the command anymore. FOO=$(docker-compose exec nginx echo true) bash -c 'echo $FOO | grep false' will output true. For a sanity check, just run FOO=$(echo true) bash -c 'echo $FOO | grep false' and it outputs nothing.

Describe the results you expected:

To be able to capture docker-compose exec command output in a variable, use it in a pipe or redirect to a file.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker compose version:

Docker Compose version 2.2.3

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
  compose: Docker Compose (Docker Inc., 2.2.3)

Server:
 Containers: 5
  Running: 4
  Paused: 0
  Stopped: 1
 Images: 54
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: false
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 1407cab509ff0d96baa4f0eb6ff9980270e6e620.m
 runc version: v1.0.3-0-gf46b6ba2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.14-1-lts
 Operating System: Arch Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.53GiB
 Name: chamon-anarchy
 ID: C6IX:KAHG:U45S:UDYA:G3OE:FO5M:ZCDK:PLCI:JKNO:XVD5:YTL3:3IGA
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions