cron job to start docker process and stop docker process

Say I have a mongodb docker process running after the below command:

docker run --name my-mongo -d mongo

Now I wish I could start this same docker process (same ID) everyday at 6am and stop it everyday at 6pm. Here is what I did in the cron:

  • What does BandwidthIn and BandwidthOut graph represent for a service?
  • Elastic search not working as expected
  • How do I combine several images into one?
  • Error response from daemon: network myapp not found
  • Git clone via HTTPS not working in Docker makefile
  • Saving docker container image
  • crontab -e
    0 18 * * * /usr/bin/docker stop my-mongo
    0 6 * * *  /usr/bin/docker start my-mongo
    

    But it didn’t run as expected, how to make it works?

    Note:
    I wish not to runt the mongo daemon with cron inside the docker container cause it is very complicated process.

    I am using root account and this is CentOS linux.

    Update

    It turns out my crond service is not running, after run service crond start and everything works.

  • Ansible Docker Container - Clone Private Repo
  • How to do gracefully shutdown on dotnet with docker?
  • Plotting R objects within docker container
  • How to define a disk quota for docker containers?
  • Visual Studio 2017 Docker project on Windows volumes issue
  • Acclerate docker pull in China/Asia
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.