如何启动docker容器(ubuntu映像) [英] How to start a docker container (ubuntu image)

查看:822
本文介绍了如何启动docker容器(ubuntu映像)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对码头容器进行统计。我使用

docker run -d -P -v / Users / bsr创建了它:/ usr / local / users --name test ubuntu

我已经安装了虚拟机客户端加载,并且安装工作。但是,我不知道为什么我不能保持shell运行。

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] $ 



编辑:



可能是因为命令(/ bin / bash ??)立即完成。当我尝试,

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

推荐答案

如果你想运行交互过程中,您应该使用 -i (保持 stdin 打开,以防分开)和 -t (分配一个伪tty)标志:

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容器(ubuntu映像)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆