简体   繁体   中英

How to start a docker container (ubuntu image)

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 ??

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.

您可以从使用简单的命令开始。

docker run "CONTAINER_ID"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM