Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on "docker-compose" when I use by pipe with sh ( echo "docker-compose... " | sh )

I've a application which has multi container. to easy installation, I decide to use packaging image. what I expected is like below

$ docker run my_application install | sh 

-> pull all related images from registry

$ docker run my_application up | sh

-> do some initial job and up all of containers

But I'm stucked with below problem.

$ 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

error raised from docker-compose. when trying like below, it 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

but when I use pipe with docker-compose it always put the error.

Does someone have any idea how I can handle this ?

like image 646
keyolk Avatar asked Apr 20 '16 04:04

keyolk


1 Answers

I see the same problem when trying to export from postgres with:

docker-compose exec postgres pg_dumpall -U postgres | gzip > file.gz

Adding the -T option to exec didn't help as it stops the pipe from working. (Actually, I'm not sure the pg_dumpall command runs at all, but it doesn't error)

The temporary solution is to use docker itself, so you'll need to change the command and container name, as:

docker exec fullname_postgres_1 pg_dumpall -U postgres | gzip > file.gz
like image 198
Matthew Wilcoxson Avatar answered Oct 16 '22 02:10

Matthew Wilcoxson