如何告诉docker-compose exec从stdin读取?
从stdin
读取时, docker-compose exec
失败:
$ echo "use mydb; show measurements;" | docker-compose exec influxdb influx Connected to http://localhost:8086 version 1.2.4 InfluxDB shell version: 1.2.4 > Traceback (most recent call last): File "/usr/local/bin/docker-compose", line 9, in <module> load_entry_point('docker-compose==1.9.0', 'console_scripts', 'docker-compose')() File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 65, in main command() File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 117, in perform_command handler(command, command_options) File "/usr/local/lib/python2.7/dist-packages/compose/cli/main.py", line 462, in exec_command pty.start() File "/usr/local/lib/python2.7/dist-packages/dockerpty/pty.py", line 338, in start io.set_blocking(pump, flag) File "/usr/local/lib/python2.7/dist-packages/dockerpty/io.py", line 32, in set_blocking old_flag = fcntl.fcntl(fd, fcntl.F_GETFL) ValueError: file descriptor cannot be a negative integer (-1)
使用-T
标志摆脱了这个问题,但似乎压制从标准input读取:
$ echo "use mydb; show measurements;" | docker-compose exec -T influxdb influx
(我需要杀死那个命令,因为它什么都不显示,也不能从stdin
读取)
这看起来像是一个docker-compose
错误,也许我应该提交这个?
$ docker-compose --version docker-compose version 1.9.0, build 2585387
编辑
有关:
- https://github.com/docker/compose/issues/3352
- https://github.com/docker/compose/issues/4290
在https://github.com/docker/compose/issues/3352 endzymebuild议使用docker命令来做到这一点。 我根据他的build议在我的bashconfiguration文件中创build了一个小小的bash函数:
# Like `docker-compose exec` but forwarding stdin to the container # See https://github.com/docker/compose/issues/3352 function docin() { local service="$1"; shift docker exec -i $(docker-compose ps -q $service) $@ }
在你的情况下,你会像这样使用它:
echo "use mydb; show measurements;" | docin influxdb influx
这是一个足够好的解决scheme,直到他们解决这个问题在docker-compose
。