container - 为了让docker容器一直运行难道要写个死循环的程序?
ringa_lee
ringa_lee 2017-04-24 09:09:36
0
9
1640

为了让docker容器一直运行难道要写个死循环的程序?
我想让容器一直运行

ringa_lee
ringa_lee

ringa_lee

reply all(9)
Peter_Zhu
$ docker run -d --name test_sleep_infinity your_image sleep infinity
# enter the container
$ docker exec -it test_sleep_infinity /bin/bash
PHPzhong
docker run -d .....

-d parameter is to keep docker running in the background,

Peter_Zhu

If your run command can run continuously and cannot be stopped after running like ls, then just add -d

小葫芦

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.

迷茫

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      
黄舟

You can just run a program in the foreground, or use supervisor to manage running programs

洪涛

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

巴扎黑

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

黄舟

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template