Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I keep a docker debian container open?

I want to use a debian Docker container to test something, and by this I mean execute some commands in the debian bash console. I tried downloading the image using docker pull debian and then running it using docker run debian, but I get no output. What am I doing wrong? Shouldn't the docker container stay open until I close it?

like image 566
sgarcia.dev Avatar asked Jan 18 '16 20:01

sgarcia.dev


People also ask

How do I keep my Debian container running?

Dockerfile Command to Keep the 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 you keep a container from exiting?

According to this answer, adding the -t flag will prevent the container from exiting when running in the background. You can then use docker exec -i -t <image> /bin/bash to get into a shell prompt.

How do I run a docker container without stopping?

Press Ctrl-P, followed by Ctrl-Q, to detach from your connection. You'll be dropped back into your shell but the previously attached process will remain alive, keeping your container running.

How do I run a Ubuntu container from a docker container?

Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. docker run -d -t ubuntu Method 2: You can run the container directly passing the tail command via arguments as shown below. docker run -d ubuntu tail -f /dev/null

Why won't my Docker container stop running?

The problem is that some application does not run in the foreground. In this situation, you can add tail -f /dev/null to your command. By doing this, even if your main command runs in the background, your container doesn’t stop because tail is keep running in the foreground. docker run -d swarm tail -f /dev/null

Do I need to keep a docker container alive?

(Obviously this is for dev purposes only, you shouldn't need to keep a container alive unless it's running a process eg. nginx...) Show activity on this post. I just had the same problem and I found out that if you are running your container with the -t and -d flag, it keeps running. Here is what the flags do (according to docker run --help ):

How do I run a docker container on sleep mode?

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.


1 Answers

You need to explicitly run bash:

docker run -it debian /bin/bash 

The -i means "run interactively", and -t means "allocate a pseudo-tty".

A good place to read a bit more is the section Running an interactive shell in the Quickstart documentation.

like image 85
Bryan Oakley Avatar answered Oct 03 '22 11:10

Bryan Oakley