“退出"后如何保留docker alpine容器用来? [英] How to retain docker alpine container after "exit" is used?
问题描述
例如,如果我使用命令 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)
那么我怎样才能再次访问同一个容器呢?当我再次运行该命令时,我得到了一个新的 alpine.
So how can I access the same container again? When I run that command again, I get a fresh alpine.
请帮忙
推荐答案
拉一张图片
docker image pull alpine
看到图片在那里
docker image ls OR just docker images
看看高山里面有什么
docker run alpine ls -al
现在你的问题是如何留在 shell 中
Now your question is how to stay with the shell
docker container run -it alpine /bin/sh
您在 shell 脚本命令行中.某些发行版可能有 bash shell.
You are inside shell script command line. Some distribution may have bash shell.
docker exec -it 5f4 sh
/ # (<-- you can run linux command here!)
此时可以使用alpine的命令行做
At this point, you can use command line of alpine and do
ls -al
输入exit出来-您可以在分离模式下运行它,它会继续运行.
type exit to come out- You can run it in detached mode and it will keep running.
使用exec命令我们可以再次登录
With exec command we can login again
docker container run -it -d alpine /bin/sh
验证它是UP并复制容器ID的前2个-3位
verify that it is UP and copy the FIRST 2 -3 digits of the container ID
docker container ls
使用 exec 命令登录
login with exec command
docker exec -it <CONTAINER ID or just 2-3 digits> sh
您需要停止,否则它将继续运行.
You will need to STOP otherwise it will keep running.
docker stop <CONTAINER ID>
这篇关于“退出"后如何保留docker alpine容器用来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!