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

[BUG] docker compose exec/run -i/-t/-T flags are inconsistent with docker exec/run #10228

Closed
jedwards1211 opened this issue Feb 1, 2023 · 5 comments

Comments

@jedwards1211
Copy link

jedwards1211 commented Feb 1, 2023

Description

The inconsistent behavior of -i/-t/-T flags in docker exec(/run) and docker compose exec(/run) is a frustrating cognitive burden.

In at least four cases (no flags when stdin is tty; and when stdin is piped: no flags, -i flag, -T flag) the behavior of docker exec/docker compose exec is inconsistent.
Is the inconsistency desirable for any reason? I think they should be completely consistent.

I haven't fully investigated the differences between docker run/docker compose run but I assume they're about the same.

Steps To Reproduce

> cat docker-compose.yaml 
services:
  db:
    image: postgres:14
    container_name: db
    environment:
    - POSTGRES_PASSWORD=woinekbjaksldf8
> docker compose up -d
[+] Running 1/1
 ⠿ Container db  Started                                                   0.5s

################
# STDIN IS TTY, NO FLAGS

> docker         exec    db psql -U postgres
# (no output)

> docker compose exec db psql -U postgres
# (goes into interactive terminal mode)

################
# STDIN IS PIPED, NO FLAGS

> echo 'SELECT 1;' | docker         exec    db psql -U postgres
# (no output)

> echo 'SELECT 1;' | docker compose exec    db psql -U postgres
the input device is not a TTY

################
# STDIN IS PIPED, -i flag

> echo 'SELECT 1;' | docker         exec -i db psql -U postgres
 ?column? 
----------
        1
(1 row)

> echo 'SELECT 1;' | docker compose exec -i db psql -U postgres
the input device is not a TTY

################
# STDIN IS PIPED, -T flag

> echo 'SELECT 1;' | docker         exec -T db psql -U postgres
unknown shorthand flag: 'T' in -T
See 'docker exec --help'.

> echo 'SELECT 1;' | docker compose exec -T db psql -U postgres
 ?column? 
----------
        1
(1 row)

Compose Version

> docker compose version
Docker Compose version v2.15.1
> docker-compose version
Docker Compose version v2.15.1

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.10.0)
  compose: Docker Compose (Docker Inc., v2.15.1)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.17)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.23.0)

Server:
 Containers: 10
  Running: 3
  Paused: 0
  Stopped: 7
 Images: 81
 Server Version: 20.10.22
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 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: 9ba4b250366a5ddde94bb7c9d1def331423aa323
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.674GiB
 Name: docker-desktop
 ID: ZY3H:2EWQ:JKLX:AMZ3:CX6T:AEF3:CCMR:QMUJ:6TUG:CRR3:5BMJ:FGNT
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

@ndeloof
Copy link
Contributor

ndeloof commented Feb 6, 2023

docker compose exec indeed has opposite default values regarding TTY and interactive mode vs docker exec, for legacy reasons. For backward compatibility, we can't change this now.
We added support for -i and -t in compose so that users can use the same flags they (mostly always) set on docker exec, while they are not required.

@ndeloof ndeloof removed the kind/bug label Feb 6, 2023
@jedwards1211
Copy link
Author

Maybe we could have an option to opt into consistent behavior instead of having backward compatibility, that we could set in some kind of global configuration file?

@ndeloof
Copy link
Contributor

ndeloof commented Feb 7, 2023

The question then is to know which of docker exec or docker compose exec is the desired behavior :)
But having defaults to change based on some configuration file would be very confusing imho.

With current flags, you can set -it everywhere for a consistent UX and get the expected result. That's a reasonable compromise.

@ndeloof ndeloof closed this as completed Feb 9, 2023
@jedwards1211
Copy link
Author

jedwards1211 commented Feb 9, 2023

You're only addressing one of the two use cases.
The opposite case (where you want to pipe to the command) doesn't have a consistent set of flags you can use though. You still have to use -T for compose. Maybe docker cli should support that flag as no-op.

@jedwards1211
Copy link
Author

Are the docker clis really going to maintain backward compatibility forever?

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

No branches or pull requests

2 participants