6

Consider a snippet:

---
version: '3.4'
services:
  app:
    image: my_image
    command: ["sleep", "60s", "&&", "my_command"]

Gives me:

sleep: invalid time interval �my_command’
Try 'sleep --help' for more information.

What is wrong? Why did this happen?

Docker version 19.03.2, build 6a30dfc
Host OS - windows 10
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Cherry
  • 31,309
  • 66
  • 224
  • 364

2 Answers2

14

You may use it like this to run sleep 60 followed by your command:

---
version: '3.4'
services:
  app:
    image: my_image
  command: sh -c "
     sleep 60 &&
     my_command"

When you run command: ["sleep", "60s", "&&", "my_command"] it passes all the arguments from position 2 onwards to sleep command. It is actually attempting to run your command as:

sleep '60s' '&&' 'uname'
anubhava
  • 761,203
  • 64
  • 569
  • 643
3

If you are using older version of docker-compose that you can try this.

version: '3.4'
services:
  foo:
    image: alpine
    command:
      - /bin/sh
      - -c
      - |
          echo "sleep for 10sec"
          sleep 10 
          your_command
Adiii
  • 54,482
  • 7
  • 145
  • 148