compose: error on launching docker-compose by piping to sh ( echo 'docker-compose ... ' | sh )
I’ve a application which has multi container. to easy installation, I decide to use package image which contains docker-comopse.yaml file. what I expected is like below
$ docker run my_application install | sh
this will pull all related image
$ docker run my_application up | sh
this will do “docker-compose up” and some intial job for application using “docker-compose exec”
But I got below error
$ echo "docker-compose exec cassandra cqlsh -e 'desc keyspaces'" | sh
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "compose/cli/main.py", line 57, in main
File "compose/cli/main.py", line 108, in perform_command
File "compose/cli/main.py", line 353, in exec_command
File ".tox/py27/lib/python2.7/site-packages/dockerpty/pty.py", line 338, in start
File ".tox/py27/lib/python2.7/site-packages/dockerpty/io.py", line 32, in set_blocking
ValueError: file descriptor cannot be a negative integer (-1)
docker-compose returned -1
and I confiremd that below two commands works well
$ echo "docker exec my_application_cassandra_1 cqlsh -e 'desc keyspaces'" | sh
system_traces system
$ sh -c "docker-compose exec cassandra cqlsh -e 'desc keyspaces'"
system_traces system
Does someone have any idea why the error comes?
below is my version info and logs from docker-compose
$ docker version
Client:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Sat Mar 12 19:18:57 2016
OS/Arch: linux/amd64
Server:
Version: 1.10.3
API version: 1.22
Go version: go1.5.3
Git commit: 20f81dd
Built: Sat Mar 12 19:18:57 2016
OS/Arch: linux/amd64
$ docker-compose version
docker-compose version 1.7.0rc1, build 1ad8866
docker-py version: 1.8.0-rc2
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
$ sh -c "docker-compose --verbose exec cassandra cqlsh -e 'desc keyspaces'"
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.auth.load_config: Found 'auths' section
docker.auth.auth.parse_auth: Found entry (registry=u'dtr.test.org', username=u'keyolk')
docker.auth.auth.parse_auth: Found entry (registry=u'test.org', username=u'$oauthtoken')
compose.cli.command.get_client: docker-compose version 1.7.0rc1, build 1ad8866
docker-py version: 1.8.0-rc2
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
compose.cli.command.get_client: Docker base_url: http+docker://localunixsocket
compose.cli.command.get_client: Docker version: KernelVersion=4.3.2-0-vanilla, Os=linux, BuildTime=2016-03-12T19:18:57.542338402+01:00, ApiVersion=1.22, Version=1.10.3, GitCommit=20f81dd, Arch=amd64, GoVersion=go1.5.3
compose.cli.verbose_proxy.proxy_callable: docker containers <- (filters={u'label': [u'com.docker.compose.project=insator', u'com.docker.compose.service=cassandra', u'com.docker.compose.oneoff=False', u'com.docker.compose.container-number=1']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker exec_create <- (u'63c121aa356c5435a9bae43c08cd805268f7253734d44e01aa2d044a41304253', ['cqlsh', '-e', 'desc keyspaces'], tty=True, stdin=True, privileged=False, user=None)
compose.cli.verbose_proxy.proxy_callable: docker exec_create -> {u'Id': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725'}
compose.cli.verbose_proxy.proxy_callable: docker exec_start <- ({u'Id': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725'}, tty=True, socket=True)
compose.cli.verbose_proxy.proxy_callable: docker exec_start -> <socket object, fd=7, family=1, type=1, protocol=0>
compose.cli.verbose_proxy.proxy_callable: docker exec_inspect <- ({u'Id': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725'})
compose.cli.verbose_proxy.proxy_callable: docker exec_inspect -> {u'CanRemove': False,
u'ContainerID': u'63c121aa356c5435a9bae43c08cd805268f7253734d44e01aa2d044a41304253',
u'DetachKeys': u'',
u'ExitCode': None,
u'ID': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725',
u'OpenStderr': True,
u'OpenStdin': True,
u'OpenStdout': True,
u'ProcessConfig': {u'arguments': [u'-e', u'desc keyspaces'],
u'entrypoint': u'cqlsh',
...
compose.cli.verbose_proxy.proxy_callable: docker exec_resize <- ({u'Id': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725'}, width=190, height=42)
compose.cli.verbose_proxy.proxy_callable: docker exec_resize -> None
system_traces system
compose.cli.verbose_proxy.proxy_callable: docker exec_inspect <- ({u'Id': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725'})
compose.cli.verbose_proxy.proxy_callable: docker exec_inspect -> {u'CanRemove': False,
u'ContainerID': u'63c121aa356c5435a9bae43c08cd805268f7253734d44e01aa2d044a41304253',
u'DetachKeys': u'',
u'ExitCode': 0,
u'ID': u'638f966cd2cf003da3b6fb32238a8750c61bfe147eabd103540501e55f8af725',
u'OpenStderr': True,
u'OpenStdin': True,
u'OpenStdout': True,
u'ProcessConfig': {u'arguments': [u'-e', u'desc keyspaces'],
u'entrypoint': u'cqlsh',
...
echo "docker-compose --verbose exec cassandra cqlsh -e 'desc keyspaces'" | sh [2/22580]
compose.config.config.find: Using configuration files: ./docker-compose.yml
docker.auth.auth.load_config: Found 'auths' section
docker.auth.auth.parse_auth: Found entry (registry=u'dtr.test.org', username=u'keyolk')
docker.auth.auth.parse_auth: Found entry (registry=u'test.org', username=u'$oauthtoken')
compose.cli.command.get_client: docker-compose version 1.7.0rc1, build 1ad8866
docker-py version: 1.8.0-rc2
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
compose.cli.command.get_client: Docker base_url: http+docker://localunixsocket
compose.cli.command.get_client: Docker version: KernelVersion=4.3.2-0-vanilla, Os=linux, BuildTime=2016-03-12T19:18:57.542338402+01:00, ApiVersion=1.22, Version=1.10.3, GitCommit=20f81dd, A$ch=amd64, GoVersion=go1.5.3
compose.cli.verbose_proxy.proxy_callable: docker containers <- (filters={u'label': [u'com.docker.compose.project=insator', u'com.docker.compose.service=cassandra', u'com.docker.compose.oneo$f=False', u'com.docker.compose.container-number=1']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker exec_create <- (u'63c121aa356c5435a9bae43c08cd805268f7253734d44e01aa2d044a41304253', ['cqlsh', '-e', 'desc keyspaces'], tty=True, stdin=True$ privileged=False, user=None)
compose.cli.verbose_proxy.proxy_callable: docker exec_create -> {u'Id': u'28344216442c0d58abce8a9face0430d1551d66eed3ec95477a1b333c67faf01'}
compose.cli.verbose_proxy.proxy_callable: docker exec_start <- ({u'Id': u'28344216442c0d58abce8a9face0430d1551d66eed3ec95477a1b333c67faf01'}, tty=True, socket=True)
compose.cli.verbose_proxy.proxy_callable: docker exec_start -> <socket object, fd=7, family=1, type=1, protocol=0>
compose.cli.verbose_proxy.proxy_callable: docker exec_inspect <- ({u'Id': u'28344216442c0d58abce8a9face0430d1551d66eed3ec95477a1b333c67faf01'})
compose.cli.verbose_proxy.proxy_callable: docker exec_inspect -> {u'CanRemove': False,
u'ContainerID': u'63c121aa356c5435a9bae43c08cd805268f7253734d44e01aa2d044a41304253',
u'DetachKeys': u'',
u'ExitCode': None,
u'ID': u'28344216442c0d58abce8a9face0430d1551d66eed3ec95477a1b333c67faf01',
u'OpenStderr': True,
u'OpenStdin': True,
u'OpenStdout': True,
u'ProcessConfig': {u'arguments': [u'-e', u'desc keyspaces'],
u'entrypoint': u'cqlsh',
...
compose.cli.verbose_proxy.proxy_callable: docker exec_resize <- ({u'Id': u'28344216442c0d58abce8a9face0430d1551d66eed3ec95477a1b333c67faf01'}, width=190, height=42)
compose.cli.verbose_proxy.proxy_callable: docker exec_resize -> None
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "compose/cli/main.py", line 57, in main
File "compose/cli/main.py", line 108, in perform_command
File "compose/cli/main.py", line 353, in exec_command
File ".tox/py27/lib/python2.7/site-packages/dockerpty/pty.py", line 338, in start
File ".tox/py27/lib/python2.7/site-packages/dockerpty/io.py", line 32, in set_blocking
ValueError: file descriptor cannot be a negative integer (-1)
docker-compose returned -1
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 48
- Comments: 38
Links to this issue
Commits related to this issue
- Temporary fix for docker-compose bug https://github.com/docker/compose/issues/3352 — committed to Amsterdam/dataselectie by StephanZaat 8 years ago
- Temporary fix for docker-compose bug docker/compose#3352 — committed to Amsterdam/postcode by publysher 8 years ago
- Fix script de instalacion Agrego la opcion -T para instalar desde un script o cron Ver https://github.com/docker/compose/issues/3352 — committed to datosgobar/portal-base by leandro-gomez 7 years ago
- dump without TTY (cron) work around https://github.com/docker/compose/issues/3352 — committed to felixhummel/docker-etherpad-lite by deleted user 7 years ago
- dump without TTY (cron) work around https://github.com/docker/compose/issues/3352 — committed to felixhummel/kimai-in-docker by deleted user 7 years ago
- Switch dump-db to use `docker exec` `docker-compose exec` throws an exception after running a command if `docker-compose` is ran via a cron. A workaround is to run the command via `docker exec` inste... — committed to watchpoint-io/watchpoint-docker by lightster 6 years ago
- use "docker exec" because of https://github.com/docker/compose/issues/3352 — committed to uselagoon/lagoon by Schnitzel 6 years ago
- Use -T flag with docker-compose exec This prevents alloction of a pseudo-TTY when it is not necessary, as suggested in https://github.com/docker/compose/issues/3352 — committed to ryanprior/conjur-puppet-demo by ryanprior 6 years ago
- Fix renew_certificate.sh script execution in crontab. While the `renew_certificate.sh` script worked fine when I ran it manually, it didn't appear to be running via the `crontab` (based on the lack o... — committed to bennadel/DailyPrime.me by bennadel 6 years ago
- backup_cron.sh: add -T option to docker-compose exec Without it, the following error occurs when run with cron: ValueError: file descriptor cannot be a negative integer (-1) See https://github.com/... — committed to smrealms/dockerize by hemberger 6 years ago
- Remove workaround for https://github.com/docker/compose/issues/3352 — committed to Code0x58/ops-examples by Code0x58 6 years ago
- Do not allocate a pseudo-tty when running `docker-compose` See the [helm docs](https://docs.docker.com/v17.09/compose/reference/exec/) for the `-T` flag explanation. When running this as a startup... — committed to lwander/community by lwander 5 years ago
- Do not allocate a pseudo-tty when running `docker-compose` (#743) See the [helm docs](https://docs.docker.com/v17.09/compose/reference/exec/) for the `-T` flag explanation. When running this as a ... — committed to GoogleCloudPlatform/community by lwander 5 years ago
- Added -T to docker-compose call to avoid STDIN issues on cron call See https://github.com/docker/compose/issues/3352 — committed to automated-assessment/nexus_monorepo by szschaler 7 years ago
- workaround docker-compose issue See https://github.com/docker/compose/issues/3352 — committed to thisisdevelopment/laravel-base-dev by ederuiter 4 years ago
- Disable pseudo-tty allocation to fix CI See https://github.com/docker/compose/issues/3352 — committed to merc1er/bch-toolkit by merc1er 4 years ago
- use "docker exec" because of https://github.com/docker/compose/issues/3352 — committed to uselagoon/lagoon-service-images by Schnitzel 6 years ago
I could get it to work by adding the
-T
parameter to not create a Pseudo-TTY.docker-compose exec -T container_name ./build.sh
for example.for all those curious about getting around this while still getting information from docker-compose…
The -i keeps stdin open while not allotting a tty and the
ps -q
on the docker-compose provides us with the container ID we want.I assume this will provide multiple IDs if you have many running, you’ll have to do some munging to use this method.
It would appear docker-compose isn’t implicitly using a
-i
when passing the exec along.So basically, you need
-i
fordocker exec
when you are piping in data to the command.And you should not use
-t
fordocker exec
when you are piping data out from the command.And
docker-compose exec
only have-T
, which means neither-i
or-t
. But you cannot represent-i
without-t
indocker-compose
.That’s the issue, right?
<
>
-T
I’m having the same issue when running:
docker-compose exec mycontainer cmd_that_takes_stdin < my/file/with/content
Everything seems to work after all (the command executes as expected), it’s just that nasty crash that docker-compose gives me afterwards:
When I use the
-T
flag as recommended though, my command doesn’t work and I even get stuck on the docker-compose command (doesn’t return to my shell but just hangs instead).I’m having the same problem, when piping
docker-compose
output via gzip to a file. When I run the command myself in Bash, it works just fine. However, as a cron job, I’m getting the same error as you — and the same stack trace file & line numbers & function names, as you, and return code -1.Here’s the command:
(I have that line in a backup script that I run sometimes manually (works fine) and sometimes as a cron job (won’t work)).
Now I’ve worked around my problem by calling Docker directly like so:
— works fine from both Cron and manually in Bash.
reproduced by gitlab-ci
Same here.
docker-compose exec
fails when running as part of a Jenkins job (works locally), butdocker exec
works. Thanks @paolomainardi !I can reproduce this bug just when docker-compose gets called from jenkins or gitlab-ci
I’d say that the problem is that
-T
indocker-compose exec
is mostly equivalent to not using any of-t
or-i
flags indocker run
, so with-T
there is not tty but also not attached stdin, and it seems that there is no way of attaching stdin without tty in docker-compose.docker-compose exec
should probably have different flags for tty and for attaching stdin asdocker run
has.same problem on jenkins, solved by using -T: docker-compose exec -T container_name cmd
I have the same problem, but just by launching this from jenkins (it fails just there):
docker-compose exec drupal bash -c "bin/behat --profile=ci"
, now changed todocker exec ${COMPOSE_PROJECT_NAME}_drupal_1 bash -c "bin/behat --profile=ci"
.now I try in cron (again) crontab -e
now I have same problem in cron (again)
after add into
crontab -e
https://stackoverflow.com/a/10657111/7670492
I try again with
-T
success
So, as I understand,
docker exec
is the solution for now?Just want to leave this minimal test-case for docker-compose:
It triggers error:
echo 123 | docker exec -i $(docker-compose ps -q service) cat -
for now…For people who are stumbling into this while trying to run
docker-compose exec
on Jenkins pipeline like myself:The
-T
flag mentioned bypasses the error, but it does not actually execute the command for me. Jenkins just thinks the command executed successfully and moves on.I had to fall back to
docker exec
, like so:The
$CONTAINER_PREFIX
is a workaround to get the docker compose prefix. It’s not pretty, and a little too verbose, but it’s the only way I could get it to work for me.env: ansible playbook + ubuntu(vagrant)
error:
add
-T
fix the issue.-T
isn’t working for me. My only workaround is to usedocker exec
directly but means I have to parse the container ID fromdocker ps
which isn’t ideal.To test I have a basic python script that just prints stdin
also fails for me, but with
-T
it just produce empty file, so no any output! Even there no error, it is unusable.
I think he means you can use
docker-compose ps -q {app}
to get the container ID. For example,I’m running into this exact issue as well. Would love to be able to pipe data into containers via docker-compose.
Have you tried adding the -T flag to docker-compose exec?