为了让docker容器一直运行难道要写个死循环的程序?
我想让容器一直运行
天蓬老师2017-04-24 09:11:36
$ docker run -d --name test_sleep_infinity your_image sleep infinity
# enter the container
$ docker exec -it test_sleep_infinity /bin/bash
PHPz2017-04-24 09:11:36
docker run -d .....
-d parameter is to keep docker running in the background,
天蓬老师2017-04-24 09:11:36
If your run command can run continuously and cannot be stopped after running like ls, then just add -d
高洛峰2017-04-24 09:11:36
If you want to use -d to run in the background, you can currently only use the command that can run continuously, otherwise it will stop when the operation is completed.
迷茫2017-04-24 09:11:36
I don’t particularly understand your scenario. I see that you have asked several docker-related questions. I will give you a few commands for your reference. I hope they are useful to you.
创建启动容器 docker run -itd <image-di> /bin/bash
单纯启动容器 docker start <container-id>
连接容器 docker attach <container-id>
回到宿主机 ctrl+p,ctrl+q
黄舟2017-04-24 09:11:36
You can just run a program in the foreground, or use supervisor to manage running programs
PHP中文网2017-04-24 09:11:36
You can do this
CMD tail -f /var/log/cron.log
Run a continuous output task in DockerFile
Okay, this is almost an infinite loop
docker ps -a
Here you can see the running status of docker, up means it keeps running, and exit means it exits after it finishes running. Docker will exit when it finishes running the task you want it to perform. So you have to write a continuous Command
巴扎黑2017-04-24 09:11:36
Even if -d is added, as long as the command is finished, docker will think that it has nothing to do, so it will automatically exit. To make the container run in the background, it is necessary to have a foreground process.
You can add top, tail, etc. after the command to always be in the foreground. Running process
黄舟2017-04-24 09:11:36
Let me go, everyone upstairs did not understand what the original poster meant. . . What he means is that there is no continuous running inside docker (i.e. running in the background).
If you want docker to keep running without exiting, you can use supervisord