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:

  • Do not download all Maven dependencies on a Docker build
  • My docker container isn't starting on localhost (0.0.0.0) on Docker for Windows (Native using Hyper-V)
  • Is it possible to access a hardware device with a docker image under Windows?
  • How to add user with dockerfile?
  • How do I edit files in a docker image?
  • https is not working on httpd docker container
  • 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.

  • Openshift : pods not being deleted
  • what are the advantages of running docker on a vm?
  • Unable to run Docker within another Docker container
  • docker insecure registry daemon not using flag
  • Docker Cannot start container port has already been allocated
  • How to encrypt docker images or source code in docker images?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.