Cannot start interactive shell (e.g. /bin/bash
) using docker-compose -f - exec
Output of docker-compose version
docker-compose version 1.25.4, build unknown
docker-py version: 4.2.0
CPython version: 3.8.2
OpenSSL version: OpenSSL 1.1.1e 17 Mar 2020
Output of docker version
Client:
Version: 19.03.8-ce
API version: 1.40
Go version: go1.14
Git commit: afacb8b7f0
Built: Mon Mar 16 22:23:09 2020
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.8-ce
API version: 1.40 (minimum version 1.12)
Go version: go1.14
Git commit: afacb8b7f0
Built: Mon Mar 16 22:22:53 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.3.3.m
GitCommit: d76c121f76a5fc8a462dc64594aea72fe18e1178.m
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
#!/bin/bash
read -d '' COMPOSE_FILE << EOF
version: '3'
services:
hello:
image: "redis:alpine"
EOF
echo "$COMPOSE_FILE"
echo "$COMPOSE_FILE" | docker-compose -f - up -d
echo "$COMPOSE_FILE" | docker-compose -f - exec hello /bin/sh
the input device is not a TTY
interactive shell starts
you can try either:
export COMPOSE_INTERACTIVE_NO_CLI=1
or run:
docker-compose exec -T ...
see discussion: #5696
@lingster neither of those works:
export COMPOSE_INTERACTIVE_NO_CLI=1
results in error:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/dockerpty/pty.py", line 334, in start
self._hijack_tty(pumps)
File "/usr/lib/python3.8/site-packages/dockerpty/pty.py", line 373, in _hijack_tty
pump.flush()
File "/usr/lib/python3.8/site-packages/dockerpty/io.py", line 367, in flush
read = self.from_stream.read(n)
File "/usr/lib/python3.8/site-packages/dockerpty/io.py", line 121, in read
return os.read(self.fd.fileno(), n)
File "/usr/lib/python3.8/socket.py", line 718, in fileno
self._checkClosed()
ValueError: I/O operation on closed file.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/docker-compose", line 11, in <module>
load_entry_point('docker-compose==1.25.4', 'console_scripts', 'docker-compose')()
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 72, in main
command()
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 128, in perform_command
handler(command, command_options)
File "/usr/lib/python3.8/site-packages/compose/cli/main.py", line 519, in exec_command
pty.start()
File "/usr/lib/python3.8/site-packages/dockerpty/pty.py", line 338, in start
io.set_blocking(pump, flag)
File "/usr/lib/python3.8/site-packages/dockerpty/io.py", line 32, in set_blocking
old_flag = fcntl.fcntl(fd, fcntl.F_GETFL)
File "/usr/lib/python3.8/site-packages/dockerpty/io.py", line 351, in fileno
return self.from_stream.fileno()
File "/usr/lib/python3.8/site-packages/dockerpty/io.py", line 103, in fileno
return self.fd.fileno()
File "/usr/lib/python3.8/socket.py", line 718, in fileno
self._checkClosed()
ValueError: I/O operation on closed file.
-T
switch just silences the error and nothing happens
Experiencing the same issue!
I'm experiencing this issue when running a docker-compose exec
command from a crontab cronjob.
I am trying to backup a database from MySQL image and I am getting the same issue.
docker-compose exec db-service mysqldump -u root -proot db > ./db.sql
I'm experiencing this issue when running a
docker-compose exec
command from a crontab cronjob.
docker-compose exec -T
solved the issue for me.
Got similar problem, when was trying to run laravel schedule in docker via cron.
My solution is type in host terminal: crontab -e
add this line: * * * * * cd /path/to/docker.yml && docker exec <docker-container's name> php artisan schedule:run >> log.txt 2>&1
save and look at log.txt
I ran into this problem in a GCP environment in a startup script, where I didn't even see the error. -T
solved my problem.
Most helpful comment
docker-compose exec -T
solved the issue for me.