Reputation: 18790
I try to start container with following command
sudo docker run ubuntu
after that I checked with
sudo docker ps -a
found the container exited already
why does it exit?
How could I keep it running in backgroud without specifying -it and attach to it on demanding?
Upvotes: 19
Views: 20940
Reputation: 101
You can add the tail command while running the container.
docker run -d ubuntu tail -f /dev/null
Upvotes: 3
Reputation: 18790
Solved by myself, a elegant way to keep the container running and waiting for further "attach" or "exec" is the following (to keep the STDIN open by -i option)
docker run -i -d ubuntu
Upvotes: 40
Reputation: 8683
You need to start an application with the docker run command that won't exit.
Example:
docker run -d --entrypoint '/bin/bash cat' ubuntu
Upvotes: 4
Reputation: 32216
the correct syntax is
(from docker run --help
)
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
you have forgotten to specify a command.
You should have a look at the docker hub
https://registry.hub.docker.com/
For example for nginx, if you look at
https://hub.docker.com/_/nginx/
you will find
docker run --name some-nginx -v /some/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
If you look at
https://github.com/nginxinc/docker-nginx/blob/7f3ef0927ec619d20181e677c97f991df0d7d446/Dockerfile
you will notice that the last line of the Dockerfile is
CMD ["nginx", "-g", "daemon off;"]
This means that when you launch the docker image nginx, the implicit action is to start nginx.
Upvotes: 0
Reputation: 1707
If you want the container to not exist, you have to use the -d
argument
So it look like this:
docker run -d ubuntu
Upvotes: -3