I am having trouble running the following in docker-compose (1.7 build 0d7bf73 , compose file format version 1) which works fine from command line (docker 1.10.3):
docker run --rm --entrypoint="/bin/bash" node:4 -c "node gridd.js -t | ./node_modules/bunyan/bin/bunyan"
My docker compose:
grid:
image: node:4-slim
entrypoint: /bin/bash
command: -c "node gridd.js -t | ./node_modules/bunyan/bin/bunyan"
Using this docker-compose file results in
marcel@client ~/grid $ docker-compose -f ../docker-compose-test.yml -p test up
Removing test_grid_1
Recreating 4e0104efc149_4e0104efc149_4e0104efc149_test_grid_1
ERROR: for grid Container command not found or does not exist.
Attaching to
I also tried using the exec method, docker-compose command as list with the same results
In 2021, with docker-compose
v2.0.0-beta.6:
Behaviour of the command
field is surprising, if |
or &&
are involved.
Expected
I can freely use piping and &&
in the commands; they would be poured to bash -c
.
I think this is the Docker normal; there behaviour of command
field is different between providing it as a string vs. as an array.
Actual
The command seems simply to get cut at |
or &&
, and the tail ignored!!!
What's bad is that there's no error about this. Also, did not find any documentation telling how exactly the command
contents are used (in Docker, there is such documentation).
Experimentation (below) shows that if I start the command with bash -c
explicitly, I can use |
and &&
in the commands.
Note: Behaviour is the same with syntax version 3.9 (latest).
version: '3.0'
services:
abc:
image: debian:latest
#command: 'echo a | grep -v a' # a (wrong)
#command: 'echo a | grep x' # a (wrong)
#
#command: bash -c 'echo a | grep -v a' # (empty) 👍
#command: bash -c 'echo a | grep a' # a 👍
command: bash -c 'echo a && false' # (exits with code 1) 👍
To test:
docker-compose.yml
docker compose up
Note: With slightly longer commands, one ends up doing quote escape trickery if the full command is also quoted. Thus, I left
bash -c
without quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With