问题描述:

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

https://docs.docker.com/articles/basics/

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

# 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?

网友答案:

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.

相关阅读:
Top