Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep ubuntu image running?

Tags:

docker

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?

like image 476
Hello lad Avatar asked Sep 14 '15 14:09

Hello lad


People also ask

How do I keep my Ubuntu container running?

Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.

How do I keep my docker container from exiting?

If there's no terminal attached, then your shell process will exit, and so the container will exit. You can stop this by adding --interactive --tty (or just -it ) to your docker run ... command, which will let you type commands into the shell.

How do I keep my docker container running after entry point?

The easiest way to keep the container running is to change its entry point to a command that will continue running forever. Let's use tail -f /dev/null . Rechecking the running container via docker ps -a we can see that our container has been up and running for several seconds and hasn't stopped yet.

How do you keep a container running in Kubernetes?

Use this command inside you Dockerfile to keep the container running in your K8s cluster: CMD tail -f /dev/null.


2 Answers

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
like image 175
Hello lad Avatar answered Nov 15 '22 23:11

Hello lad


You need to start an application with the docker run command that won't exit.

Example:

docker run -d --entrypoint '/bin/bash cat' ubuntu

like image 28
Michael Avatar answered Nov 15 '22 23:11

Michael