3

How to stat a docker container. I had created it using docker run -d -P -v /Users/bsr:/usr/local/users --name test ubuntu I do have virtual box guest addition installed, and mounting works. But, I am not sure why I can't I keep the shell running.

bsr[~/tmp/web] $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS                   NAMES
cf620ff6c36a        ubuntu:latest       "/bin/bash"         2 hours ago         Exited (0) 2 minutes ago                           test                
8213c8d49842        nginx:latest        "nginx"             3 hours ago         Up About an hour           0.0.0.0:49154->80/tcp   web                 
bsr[~/tmp/web] $ docker start test
test
bsr[~/tmp/web] $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS                   NAMES
cf620ff6c36a        ubuntu:latest       "/bin/bash"         2 hours ago         Exited (0) 2 seconds ago                           test                
8213c8d49842        nginx:latest        "nginx"             3 hours ago         Up About an hour           0.0.0.0:49154->80/tcp   web                 
bsr[~/tmp/web] $ 

Edit:

it may be because the command (/bin/bash ??) finishes immediately. When I tried,

docker run -d -P -v /Users/bsr:/usr/local/users --name test5 ubuntu /bin/bash -c "while true; do echo Hello world; sleep 1; done"

I could get the terminal. But isn't there any way to just start a container and get to the terminal ??

bsr
  • 57,282
  • 86
  • 216
  • 316

2 Answers2

5

If you want to run an interactive process, you should use the -i (keep stdin open in case you detach) and -t (allocate a pseudo-tty) flags:

docker run -it ubuntu 

You can look at the docs for more information on those flags and their usage.

Zoltán
  • 21,321
  • 14
  • 93
  • 134
Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
  • how to show the ubuntu GUI as i have installed the container and this command this working and opening root – Shan Khan Nov 17 '16 at 14:37
0

You can start by using simple command.

docker run "CONTAINER_ID"