Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How chain sleep command in docker compose?

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
like image 246
Cherry Avatar asked Dec 14 '22 10:12

Cherry


1 Answers

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'
like image 84
anubhava Avatar answered Dec 28 '22 12:12

anubhava