linux - docker run a shell script in the background without exiting the container -


i trying run shell script in docker container. problem shell script spawns process , should continue run unless shutdown script used terminate processes spawned startup script.

when run below command,

docker run image:tag /bin/sh /root/my_script.sh 

and then,

docker ps -a 

i see command has exited. not want. question how let command run in background without exiting?

you haven't explained why want see container running after script has exited, or whether or not expect script exit.

a docker container exits container's cmd exits. if want container continue running, need process keep running. 1 option put while loop @ end of script:

while :;   sleep 300 done 

your script never exit container keep running. if container hosts network service (a web server, database server, etc), typically process runs life of container.

if instead script exiting unexpectedly, need take @ container logs (docker logs <container>) , possibly add debugging script.

if asking, "how run container in background?", emil's answer (pass -d flag docker run) out.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -