Answers: <p>You don't need cron. Most server OS-es (CoreOS, RedHat, CentOS, Ubuntu, etc.) these days run <a href="https://freedesktop.org/wiki/Software/systemd/" rel="noreferrer">systemd</a>, and systemd unit files can run your container to execute the job, for example:</p>
  
  <p>Two unit files. One is mytimedstuff.service and mytimedstuff.timer. The .timer defines when the service should be executed.</p>
  
  <p>In mytimedstuff.service</p>
  
  <pre><code>[Unit]
  Description=Executes mystuff
  After=default.target docker_network_apps.service
  Requires=default.target docker_network_apps.service
  
  [Service]
  Type=oneshot
  User=root
  ExecStartPre=/usr/bin/docker pull mystuff:stable
  ExecStartPre=-/bin/bash -c "/usr/bin/docker rm -f mystuffcontainer 2&gt;/dev/null"
  ExecStart=/bin/bash -c "/usr/bin/docker run --name mystuffcontainer mystuff:stable mystuff"
  </code></pre>
  
  <p>In mytimedstuff.timer:</p>
  
  <pre><code>[Unit]
  Description=My stuff runs at 00:10 sharp.
  
  [Timer]
  OnCalendar=00:10:00
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2018-09-05T19:12:18.877Z
Answers: 2018-09-05T19:12:18.877Z
Answers: aries1980
Answers: <p>My understanding is that you want to run multiple services in your container.</p>
  
  <p>The best practice to run several jobs is to create several containers for your different processes and manage them through docker compose this allows you to define in one file all the containers needed for your app and launch in one single command.</p>
  
  <p>Otherwise, <a href="https://docs.docker.com/config/containers/multi-service_container/" rel="nofollow noreferrer">docker docs</a> provide two simple solutions for your situation.</p>
  
  <ul>
  <li><p>Use <code>ENTRYPOINT</code> to run a single script which manage your process, <a href="https://docs.docker.com/config/containers/multi-service_container/" rel="nofollow noreferrer">see example here</a></p></li>
  <li><p>Use a process manager like <code>supervisord</code>, <a href="https://blog.trifork.com/2014/03/11/using-supervisor-with-docker-to-manage-processes-supporting-image-inheritance/" rel="nofollow noreferrer">Detailed article about using docker with Supervisor</a></p></li>
  </ul>
  
  <p>One thing to remember when doing Docker: one container, one service.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-09-07T14:26:55.410Z
Answers: Interesting - the service is still one, however, the service runs multiple co-related jobs that are dependent of each other.
Answers: Saiyam Sethi
Answers: CC BY-SA 4.0
Answers: 2018-09-07T15:25:13.530Z
Answers: I would use a bash script as entrypoint and manage this dependency within the script.
Answers: storm
Answers: CC BY-SA 4.0
Answers: 2021-07-01T12:26:07.450Z
Answers: Would you use another container to host the "controller" script?  Or would you use `cron` or `systemd` on the machine that hosts all of the containers?
Answers: craig
Answers: CC BY-SA 4.0
Answers: 2024-01-16T16:29:09.427Z
Answers: @craig Also wondering this
Answers: its.me.adam
Answers: CC BY-SA 4.0
Answers: 2018-09-07T07:51:31.003Z
Answers: 2018-09-07T07:51:31.003Z
Answers: storm
Body: <p>I have an interesting question related to scheduling my Docker Container. </p>
  
  <p>I have a virtual machine with a docker image inside of it. I can spin up a container from the image that has an entrypoint (jar). </p>
  
  <p>I am in a dilemna on how I should schedule the jobs to run against the jar. </p>
  
  <p>Here are my 2 options:  </p>
  
  <p>1) If I run a cron on the VM then I can call the docker run commands to produce a container and run different jobs against the jar. The issue here is that once a single job is run, the container automatically terminates and the second job has no previous histroy of the previously run jobs. I believe theres a way to keep a container running forever with an entry point but I haven't explored/tested this yet. </p>
  
  <p>2) I can install a cron inside of the container and through the Dockerfile provide the cron for updating - however, the issue here is how would I launch the container and keep it running for the cron jobs to run? </p>
  
  <p>If you need any further details please do let me know. </p>
  
  <p>Thanks!</p>
  
Comments: CC BY-SA 4.0
Comments: 2018-09-05T13:38:40.950Z
Comments: Why does your container terminates when your run the job?
Comments: storm
Comments: CC BY-SA 4.0
Comments: 2018-09-06T21:19:05.873Z
Comments: When you use an entrypoint in your image and you launch a container from that image - the entrypoint is used as the executable. When the executable finishes and returns an exit code - the container terminates as well
Comments: Saiyam Sethi
Tags: <docker><containers>
Title: Scheduling a Docker Container or Installing Scheduler in Container
UserDisplayName: Saiyam Sethi
ThreadText: # Scheduling a Docker Container or Installing Scheduler in Container
  
  (Asked by: username_0 on 2018-09-04)
  
  I have an interesting question related to scheduling my Docker Container.
  
  I have a virtual machine with a docker image inside of it. I can spin up a container from the image that has an entrypoint (jar).
  
  I am in a dilemna on how I should schedule the jobs to run against the jar.
  
  Here are my 2 options:
  
  1) If I run a cron on the VM then I can call the docker run commands to produce a container and run different jobs against the jar. The issue here is that once a single job is run, the container automatically terminates and the second job has no previous histroy of the previously run jobs. I believe theres a way to keep a container running forever with an entry point but I haven't explored/tested this yet.
  
  2) I can install a cron inside of the container and through the Dockerfile provide the cron for updating - however, the issue here is how would I launch the container and keep it running for the cron jobs to run?
  
  If you need any further details please do let me know.
  
  Thanks!
  
  **Tags:** docker, containers
  
  > **Comments:**
  > **username_1**: Why does your container terminates when your run the job?  
  > **username_0**: When you use an entrypoint in your image and you launch a container from that image - the entrypoint is used as the executable. When the executable finishes and returns an exit code - the container terminates as well  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2018-09-05. Score: 5
  
  You don't need cron. Most server OS-es (CoreOS, RedHat, CentOS, Ubuntu, etc.) these days run [systemd](https://freedesktop.org/wiki/Software/systemd/), and systemd unit files can run your container to execute the job, for example:
  
  Two unit files. One is mytimedstuff.service and mytimedstuff.timer. The .timer defines when the service should be executed.
  
  In mytimedstuff.service
  
  ```
  [Unit]
  Description=Executes mystuff
  After=default.target docker_network_apps.service
  Requires=default.target docker_network_apps.service
  
  [Service]
  Type=oneshot
  User=root
  ExecStartPre=/usr/bin/docker pull mystuff:stable
  ExecStartPre=-/bin/bash -c "/usr/bin/docker rm -f mystuffcontainer 2>/dev/null"
  ExecStart=/bin/bash -c "/usr/bin/docker run --name mystuffcontainer mystuff:stable mystuff"
  
  ```
  
  In mytimedstuff.timer:
  
  ```
  [Unit]
  Description=My stuff runs at 00:10 sharp.
  
  [Timer]
  OnCalendar=00:10:00
  
  [Install]
  WantedBy=multi-user.target
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2018-09-07. Score: 2
  
  My understanding is that you want to run multiple services in your container.
  
  The best practice to run several jobs is to create several containers for your different processes and manage them through docker compose this allows you to define in one file all the containers needed for your app and launch in one single command.
  
  Otherwise, [docker docs](https://docs.docker.com/config/containers/multi-service_container/) provide two simple solutions for your situation.
  
  * Use `ENTRYPOINT` to run a single script which manage your process, [see example here](https://docs.docker.com/config/containers/multi-service_container/)
  * Use a process manager like `supervisord`, [Detailed article about using docker with Supervisor](https://blog.trifork.com/2014/03/11/using-supervisor-with-docker-to-manage-processes-supporting-image-inheritance/)
  
  One thing to remember when doing Docker: one container, one service.
  
  > **Comments:**
  > **username_0**: Interesting - the service is still one, however, the service runs multiple co-related jobs that are dependent of each other.  
  > **username_1**: I would use a bash script as entrypoint and manage this dependency within the script.  
  > **username_3**: Would you use another container to host the "controller" script?  Or would you use `cron` or `systemd` on the machine that hosts all of the containers?  
  > **username_4**: @username_3 Also wondering this  
  
  ---
  
  