Search code examples
bashdockercron

Crontab can't execute script directly in container environment


I present to you the following dilemma I execute my script manually and it works well, see next line for example:

docker exec -ti backup_subversion sh -c "/tmp/my_script.sh"

But when I attempt to schedule the process this line is just skipped.

  • I have tried to execute just a touch command and it too is ignored.
  • I have tried to execute as root, same problem.
  • I have tried to execute in another docker environment: same problem.

My OS is Centos 7.

In this script for example the bug part who will crash :

#!/bin/bash

# Create a container.
docker run -d --name=backup_subversion \
-v /subversion/dump:/var/dump \
--net my_network my_server.domaine.com/subversion/billy:1.9

# I copy a script.
docker cp tools_subversion_dump.sh backup_subversion:/tmp

# This line is ignore since crontab exec.
docker exec -ti backup_subversion sh -c "/tmp/tools_subversion_dump.sh"

Thank you in advance for your answers because it's a mystery to me.


Solution

  • It's probably because you used the -it options that only apply to an interactive shell rather then a pseudo one like the one used in scripts as referenced in the question