如何在“退出"之后保留泊坞码头高山容器?用来? [英] How to retain docker alpine container after "exit" is used?

查看:111
本文介绍了如何在“退出"之后保留泊坞码头高山容器?用来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,如果我使用命令docker run -it alpine /bin/sh 它启动了一个终端,之后我可以安装软件包和所有软件包.现在,当我使用exit命令时,它会返回到终端. (主要一)

Like for example if I use command docker run -it alpine /bin/sh it starts a terminal after which I can install packages and all. Now when I use exit command it goes back to the terminal. (main one)

那么我该如何再次访问同一容器? 当我再次运行该命令时,我得到了一个新的阿尔卑斯山脉.

So how can I access the same container again? When I run that command again, I get a fresh alpine.

请帮助

推荐答案

只要指定的运行命令进程仍在运行,该容器就会存在.指定运行/bin/sh时,一旦退出,sh进程将终止,您的容器也将终止.

The container lives as long as the specified run command process is still running. When you specify to run /bin/sh, once you exit, the sh process will die and so will you container.

如果要保持容器运行,则必须保持进程内部运行.对于您的情况(我不确定您要达到的目标,我想您只是在测试),以下内容将使其保持运行状态

If you want to keep your container running, you have to keep the process inside running. For your case (I am not sure what you want to acheive, I assume you are just testing), the following will keep it running

docker run -d --name alpine alpine tail -f /dev/null

然后您可以使用进入容器

Then you can sh into the container using

docker exec -it alpine sh  

这篇关于如何在“退出"之后保留泊坞码头高山容器?用来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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