Reputation: 561
I want to run a container, but it is a background program (for example: tinyproxy, I make the image tinyproxy_local)
docker run -d tinyproxy_local tinyproxy
this will exit because tinyproxy is a background program.
I can do it like this:
docker run -it tinyproxy_local bash
/#: tinyproxy
/#: ctrl+p ctrl+q
this can be running, but I want the tinyproxy can be auto started when I restart the container. I tested it:
docker run -d tinyproxy_local tinyproxy && sleep 99999999999
I think the container can keep running when sleeping, but it don't work.
How can I run a background program in docker container, and It can be auto started when I restart the container?
Or is there any small forground program, that can keep container running?
(I have tried sleep 99999999
, but it didn't work)
Upvotes: 0
Views: 844
Reputation: 14846
You should run your docker processes in the foreground.
With tinyproxy I believe it is the -d
flag (source: https://www.mankier.com/8/tinyproxy).
Edit based on comments:
If your entrypoint runs two processes - one your app, and another the tinyproxy - you should separate them to two containers, and run tinyproxy in the foreground with the -d flag. Another source of information can be this tinyproxy docker.
Sticking to one process per container will save you headaches in the future.
Upvotes: 3