How can I keep docker container running?

Viewed 35950

I want to run multiple containers automatically and create something,

but some images, such as swarm, will automatically stop after run or start.

I already try like that

docker run -d swarm

docker run -d swarm /bin/bash tail -f /dev/null

docker run -itd swarm bash -c "while true; do sleep 1; done"

but 'docker ps' show nothing, and I tried to build Dockerfile by typing:

FROM swarm
ENTRYPOINT ["echo"]

and The image does not run with error message :

docker: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\\"echo\\\": executable file not found in $PATH\"\n".

I can't understand this error... How can I keep swarm container running..?

(Sorry,my English is not good))

6 Answers

Docker container does two type of task. One is to perform and exit & other is to run it in background.

To run docker container in background, there are few options.

  1. Run using shell. docker run -it <image> /bin/bash
  2. For continuously running container. docker run -d -p 8080:8080 <image>. Assuming image will expose port 8080 and in listening mode.

It's fine to to a tail on /dev/null, but why not make it do something useful?

The following command will reap orphan processes, so no zombie (defunct) precesses are left floating around. Also some init.d / restart scripts doesn't allow this.

exec sh -c 'while true ;do wait ;done'
Related