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:

  • Docker difference in start and stop times
  • “docker run swarm create” failed with error “503 Service Unavailable”
  • Docker, CoreOS and fleet based deployments
  • Couchdb cartridge not responding in docker image
  • Multiple projects in one solution to generate one docker container
  • openshift wso2api manager redirect error
  • 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?

    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.


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

  • Docker set read timeout for push
  • What is different of Config and ContainerConfig of docker inspect?
  • docker restart container failed: “already in use”, but there's no more docker image
  • docker root crontab job not executing
  • Update Docker image and container from Jenkins
  • spring cloud hystrix turbine amqp connection refused with docker
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.