Skip to content

[BUG] Different behavior of shell scripts using docker-compose between file input and stdin #10418

@sahib

Description

@sahib

Description

I see different behavior in running a shell script from file and from stdin (see Steps to Reproduce).

Steps To Reproduce

The shell script is simple:

echo before
docker-compose exec -T redis echo hello
echo after

The docker-compose.yaml is simple too (and can be pretty much any container with echo binary):

---
version: "3.7"

services:
  redis:
    image: "redis:latest"
    command: redis-server

If run via file, the output is expected:

$ bash script.sh
before
hello
after

If run from stdin, the output stops after the compose command:

$ bash < script.sh
before
hello

Exit code is 0 and there seems to be no error. From a quick glance I saw no difference when executed with strace. The -T (--no-TTY) seems to be the culprit and it somehow seems to cause a close of bash's stdin.

This is probably not a bug in docker-compose, but that was the closest issue template available.
I only have been able to reproduce with docker-compose though, so I'm posting here in the hope that someone can explain.

Compose Version

Docker Compose version 2.16.0

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.4
    Path:     /home/name/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  2.16.0
    Path:     /usr/lib/docker/cli-plugins/docker-compose

Server:
 Containers: 12
  Running: 3
  Paused: 0
  Stopped: 9
 Images: 85
 Server Version: 23.0.1
 Storage Driver: btrfs
  Btrfs:
 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.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 31aa4358a36870b21a992d3ad2bef29e1d693bec.m
 runc version:
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.94-1-MANJARO
 Operating System: Manjaro Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 15.14GiB
 Name: werkzeug
 ID: PUZO:S6ZB:JI3Q:BBCI:X3UH:673F:HNHY:DOHB:CDMK:NBDN:W5J2:JUA3
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions