Why docker sleep 1 for continuous background process?

I would like to do “starting a long-running worker process” as in this article

I don’t understand why sleep 1? why not sleep 86400??? one day or one year?

  • DNS issue with docker image
  • Attaching to a docker container with base image scratch?
  • Docker git clone on container launch?
  • Docker - MySQL container does not keep running
  • How to use Let's Encrypt with Docker container based on the Node.js image
  • Can't push an image to ECS Private Registry - no basic auth credentials
  • # Start a very useful long-running process
    $ JOB=$(sudo docker run -d ubuntu /bin/sh -c "while true; do echo Hello world; sleep 1; done")
    # Collect the output of the job so far
    $ sudo docker logs $JOB
    # Kill the job
    $ sudo docker kill $JOB

    What’s the “best” way to make it run as a background process for apache, nginx, mysql etc?

    Why do you need to echo? is that necessary?

  • What happens when the docker host restarts?
  • How do I use docker on Win 8.1 (boot2docker) both behind a proxy and without a proxy?
  • Cannot access ports on MacOSX host from within docker container
  • Can't CD into directory with 755 permissions?
  • Slowness in Docker container
  • How to enable/access the Confluence API from a Confluence Server running in a Docker container
  • 2 Solutions collect form web for “Why docker sleep 1 for continuous background process?”

    This job is to write Hello world to stdout every second I guess for demonstration purposes only. If you want to do something else at some different interval you have to change it accordingly.

    The key thing is the -d flag makes Docker run it in background (‘detatched’), and the docker logs lets you examine the logs as many times as you like after that point.

    For Apache, get hold of an Apache image; for Nginx use an Nginx image, and so on.

    I found this image with Nginx and PHP, and the official Docker mysql image worked for me. You’ll need to do a bit more reading to see how to integrate your data, web content, config, etc.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.